UNIX / How to organize simple backups

Home | UNIX | Practical

How to organize simple backups
pbraun@nethence.com


Introduction
Much simplier than TSM, TINA or Netbackup, the tar utility nevertheless permits to realize a consistent backup architecture : the tar files can be exported by NFS, rsync or FTP to the backup server. As for the databases, it's preferable to use their own backup tool anyway,
- RMAN for Oracle
- mysqldump for MySQL
The scripts available below may be adapted to your needs for example the $dir for the backup folder. Also note this has only being tested on Redhat systems. Other UNICES may have other commands and arguments (gtar).


The differential tar backup scripts
pbraun.nethence.com/code/backupdiff.sh
pbraun.nethence.com/code/backupfull.sh
Note. this is date +%U and crontab 7 based, with Sunday being the first day of the week. If you need to make your full backups at Monday instead, switch to date %+V, not %W, and crontab 1.
Todo. in case of a new year, backupdiff needs to use last year's full backup (dir 200XwXX)


The backups cleanup script
pbraun.nethence.com/code/backuprotate.sh
Note. backuprotate.sh is keeping the current week + the two last weeks. Configure your backup server -- which gets a copy of those by NFS or FTP -- as needed for older backups. This also keeps track of previous' year retention backups, but as I just said, the backupdiff script isn't ready for that. Testing is needed.


The /etc/backup.conf configuration file
/somedir  # comment allowed
/some/other/dir  # blahblah
/and/so/on


The /etc/backup_exclude.conf configuration file
somedir/exclude/this/subdir
some/other/dir/exclude
Note. ommit first "/"
Note. comments aren't allowed in here (used by tar -X).
Note. you could say "/" into backup.conf and "sys, proc, dev, /var/mysql" into backup_exclude.conf


MySQL backups
Just make this wrapper and call it from conrtab too
mysqldump --all-databases -p'PASSWORD' | gzip > /home/backup/`date +%Yw%U`/mysql-all-databases.`date +%Y%m%d`.gz
As for Oracle backups, use RMAN.


root's crontab
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
30 0 * * * sh /root/bin/scdaily.sh
0 4 * * 7 sh /root/bin/backupfull.sh && sh /root/bin/backupmysql.sh && sh /root/bin/backuprotate.sh
0 4 * * 1-6 sh /root/bin/backupdiff.sh && sh /root/bin/backupmysql.sh && sh /root/bin/backuprotate.sh
0 6 * * * ntpdate ntp1.dedibox.fr > /dev/null
Note "0" or "7" corresponds to Sunday
Note if you use the mysql wrapper (see above), also add && backupmysql.sh between backupfull and backuprotate.)
Note /root/bin is included in the path as we put the scripts there


References & other tools
Seems to be Disaster recovery capable : www.mondorescue.org/
Amanda (Advanced Maryland Automatic Network Disk Archiver) : www.amanda.org/
NetBSD dump/rescue,
netbsd.gw.com/cgi-bin/man-cgi?dump++NetBSD-current
netbsd.gw.com/cgi-bin/man-cgi?restore++NetBSD-current
Bacula : www.bacula.org/en/



Sat Nov 8 12:19:48 CET 2008
       © 2008 Pierre-Philipp Braun