Management Of Backups With DAT Devices - Page 2
5 Dump the files to tape.Once synchronized the servers on the local disk of the server connected to the DAT, we have to copy the data we are interested in, to a tape. This guide aims to copy all the data on each copy. Possible other solution would be an incremental backup where, each day, we will copy only those files that have changed but I will not mention about that case here.
5.1 PeriodicityThe proposal is to make a dump every day. This task will be automated using cron and we would have to put the tape in the DAT device once a day. The dump data to tape should be done after the servers synchronization, which, following this model, should be done once a day prior to dump data to tape. In addition we will also copy a tape as monthly backup. In short, we will have 5 + 12 tapes in a year, one for each working day of the week and one per month. The monthly tape will be on the first Monday of each month. The process to run a cron on the first Monday of the month is not supported directly but is obtained as follows: crontab -e Add the following line:50 10 1-7 * * [ "$(date +\%a)" == "Mon" ] && /usr/local/bin/monthly.sh This will launches the first Monday of each month, the script /usr/local/bin/monthly.sh. In the example of this guide, the only thing different that we will do the first Monday of the month is to put the 'monthly' tape. However, the script monthly.sh contains a reminder message for the person responsible for putting the tape which is sent via cron. #!/bin/bash echo "Hi!" echo echo "If I have been scripted well, today is the first Monday of the month" echo "and you must to put the monthly backup tape."
5.2 ScriptThe following script will copy the data to tape from the directory where the files are synchronized from the original server #!/bin/bash
# Dump files to tape
# Variables
# Base dir to copy
SOURCE=/backups
# Logs dir
LOGS=/var/log/backup
# Dir to copy
DIRS="serverA/var/log serverA/var/lib/mysql serverA/home/httpd"
# tape device
TAPE=st0
# Date format
FORMAT="[%Y/%m/%d %H:%M:%S]"
# End Variables
# Var for logs
DAY=`date --date='1 day ago' +%a`
MONTHDAY=`date --date='1 day ago' +%e`
# First Monday of the month?
if test "$DAY" = "Mon" -a $MONTHDAY -ge 1 -a $MONTHDAY -le 7; then
DAY=`date +%b`
fi
date=`date "+$FORMAT"`
echo "----------------------" >> $LOGS/$DAY.log
echo "----------------------" >> $LOGS/$DAY.err
echo "$date" >> $LOGS/$DAY.err
echo "----------------------" >> $LOGS/$DAY.err
echo "Message from Backup Server."
echo
echo "Below the summary of the nightly backup."
echo
echo "$date Start backup" |tee -a $LOGS/$DAY.log
echo "$date Rewinding the tape..." |tee -a $LOGS/$DAY.log
mt -f /dev/$TAPE rewind
echo "$date Starting to copy" |tee -a $LOGS/$DAY.log
for dir in $DIRS; do
date=`date "+$FORMAT"`
echo
echo "$date Started: $SOURCE/$dir" |tee $LOGS/$dir.$DAY.log
tar -vzcf /dev/n$TAPE -C $SOURCE $dir >> $LOGS/$dir.$DAY.log 2>>$LOGS/$DAY.err
wait $!
date=`date "+$FORMAT"`
echo "$date Completed: $SOURCE/$dir" |tee -a $LOGS/$dir.$DAY.log
echo
done
echo
sleep 10
echo "$date Ejecting the tape..." |tee -a $LOGS/$DAY.log
mt -f /dev/$TAPE rewoffl
date=`date "+$FORMAT"`
echo "$date End backup" |tee -a $LOGS/$DAY.log
A little analysis to understand what the script does:
6 Restoring filesRestoring files is as follows:
7 Summaries commands to use a tape device.This small list shows only the most common options; however, it is highly recommended that you go through man pages of mt and tar command for more options/information. To use the following comands, you have to be root. Otherwise, you can use them with sudo. Rewind tape drive: mt -f /dev/st0 rewind Backup directory /www and /home with tar command (z - compressed): tar -czf /dev/st0 /www /home Find out what block you are at with mt command: mt -f /dev/st0 tell Display list of files on tape drive: tar -tzf /dev/st0 Restore /www directory:
cd / Unload the tape: mt -f /dev/st0 offline Display status information about the tape unit: mt -f /dev/st0 status Erase the tape: mt -f /dev/st0 erase Go to previous record: mt -f /dev/nst0 bsfm 1 Forward record: mt -f /dev/nst0 fsf 1 Go to end of data: mt -f /dev/nst0 eod
8 ConclusionAs always in this case, I can NOT assure that it works for everyone. I CAN assure, it works exactly in this way with my Ubuntu box for 16 months, now, without any big problems.
|



Recent comments
13 hours 51 min ago
15 hours 26 min ago
19 hours 47 min ago
23 hours 38 min ago
1 day 11 hours ago
1 day 17 hours ago
1 day 20 hours ago
1 day 21 hours ago
1 day 21 hours ago
1 day 22 hours ago