Hi!, If you're new here, you may want to subscribe to our RSS feed or sign up for free email updates.. Thanks for visiting!
We should regularly backup our servers (and PCs and notebooks) and if you are running a production server, backing up as regularly as possible should be considered. However, backing corporate servers which are full of emails or shared documents can take hours. We can probably only do so on the weekends. So, what happens when we need to restore some data at the end of the work week? Does it mean that we will loose all our data that we created or modified earlier on in the week, since we only have last week’s backup?

In reality, we don’t need to do a “full” backup each time we backup our servers, we can do “differential” backups. Differential backups are basically backups of of all the changes since the last “full” backup. In other words, only the difference since the last “full” backup.
A simple script to do differential backups for users’ home directory from Monday to Thursday and full backups on a Friday is as below.
#!/bin/bash
if [ `date +%w` -eq 5 ] ; then
if tar -cf /tmp/bck-full-`date +%F`.tar /home ; then
touch /var/log/bck/last-bck
tar -tf /tmp/bck-full-`date +%F`.tar > \
/var/log/bck/bck-`date +%F`.log
else
mail -s “Backup failed” root < ~
fi
elif [ `date +%w` -gt 0 ] && [ `date +%w` -lt 5 ] ; then
find /home -type f -newer /var/log/bck/last-bck | \
tar -cf /tmp/bck-diff-`date +%F`.tar -T -
if [ $? ] ; then
tar -tf /tmp/bck-diff-`date +%F`.tar > \
/var/log/bck/bck-`date +%F`.log
else
mail -s “Backup failed” root < ~
fi
fi
Of course, you will need to ensure that those directories used are already there and run the backups as root. (Note, script edited to fit the width of this posting, so if you have errors, please leave a comment).



No comments yet.