#!/bin/sh # A FreeBSD shell script to dump Filesystem with full and incremental backups to tape device connected to server. # Tested on FreeBSD 6.x and 7.x - 32 bit and 64 bit systems. # May work on OpenBSD / NetBSD. # ------------------------------------------------------------------------- # Copyright (c) 2007 nixCraft project <http://www.cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ---------------------------------------------------------------------- LOGGER=/usr/bin/logger DUMP=/sbin/dump # FSL="/dev/aacd0s1a /dev/aacd0s1g" FSL="/usr /var" NOW=$(date +"%a") LOGFILE="/var/log/dumps/$NOW.dump.log" TAPE="/dev/sa0" mk_auto_dump(){ local fs=$1 local level=$2 local tape="$TAPE" local opts="" opts="-${level}uanL -f ${tape}" # run backup $DUMP ${opts} $fs if [ "$?" != "0" ];then $LOGGER "$DUMP $fs FAILED!" echo "*** DUMP COMMAND FAILED - $DUMP ${opts} $fs. ***" else $LOGGER "$DUMP $fs DONE!" fi } dump_all_fs(){ local level=$1 for f in $FSL do mk_auto_dump $f $level done } init_backup(){ local d=$(dirname $LOGFILE) [ ! -d ${d} ] && mkdir -p ${d} } init_backup case $NOW in Mon) dump_all_fs 0;; Tue) dump_all_fs 1;; Wed) dump_all_fs 2;; Thu) dump_all_fs 3;; Fri) dump_all_fs 4;; Sat) dump_all_fs 5;; Sun) dump_all_fs 6;; *) ;; esac > $LOGFILE 2>&1
How do I run this script?
Download this script and unzip in /root. Open script and customize tape device ($TAPE variable) and file systems ($FSL). Operator can run this script from a shell prompt:
# /root/tapebackup.sh
Or via a cron job:
@midnight /root/tapebackup.sh
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 14 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Hey Sir,
Do you train students ? Would like to learn from the best!
Sincerely,
Gaelle
Hi Aaron
I’m customizing your script to my site. Where can I find the tapeswap.sh script?
thanks
It’s still very useful
I’ve updated the above to include lockfile management, enabling setting snapshot only days, tape full days and, tape incremental days or just to skip certain days. You can see the full script here: http://woodstock.anbcs.com/shell/dobackup.sh
Thanks again Vivek for giving me the motivation to get that setup…it’s been a real lifesaver for us here.
— Aaron
It doesn’t like my tags … guess I don’t have html tag permissions ;p
You need to put them between pre tags. BTW, I’ve edited out your post. Thanks for sharing your solution.
No problem, just a little update I basically rewrote it again and think I finally have what I really want. I use ZFS here on my freebsd system and I wanted to make sure 1) my backups were sane and stable ….and 2) I didn’t want to always have to goto tape to grab a file unless there was just a total catastrophic failure. Hence I integrated ZFS snapshot creation into the process. Then just to make the archives pretty, I told tar to transform the snapshot paths to the actual system paths before writing it to tape. This uses the same code for tapeswap…here it is…
Err…that’s not exactly what I wanted…guess [code] tags aren’t supported here. It looses all the formatting/tabs like that…but it should still work just doesn’t look very pretty.
I’ve edited out your script and posted using <pre> … </pre> tags
Thanks for sharing your code!
This gave me a the motivation to finally get around to writing a backup script for my server. It’s basic framework is a combination of this script and another one I found on this site. It’s optimized for a freebsd/zfs system with a local tapedrive…it’ll even automatically eject tapes and resume on a new tape load. Hope it helps someone.
Main Part:
Not sure if anyone else could use it…but I hope it helps someone get a start anyways.
Inspired by your script I wrote a new one. It can be found on my blog.
That’s very handy! Two questions: the `die()’ routine doesn’t seem to be used by anything? And `BAK’ seems to be undefined.
I’ll use this as a base for a modified script (I save dumps onto a separate hard drive, and also want there to be separate dump files for each filesystem being dumped).
Actually I’ve two scripts, BAK was used to dump to $BAK file system (e.g. BAK=/usr/backup) and another for tape. $BAK and die are from my dump to FS. Feel free to modify it as per your setup. I will update script to avoid confusion.
Nice script
Can it be ported to solaris 10
It should work under Solaris too with little changes.