![]() |
1. GoalYou can find many others backup solutions in this Wiki, each of them fitting a given context. My contextI tested this procedure with my Linksys NSLU2, with Openslug 2.7 beta.
The challenge
My requirements
2. An overview of the solutionAll my requirements all together could seem insane. The idea is the following (thanks to all the guys that proposed that idea on Internet) :
The rest is only scripting... 3. PrerequisitesI tested this procedure with my Linksys NSLU2, with Openslug 2.7 beta. You need some optware packages already installed : ipkg update to have a real scripting capability ipkg install bash to schedule the backups ipkg install cron to receive the result of the backup by mail
to perform the backup ipkg install rsync 4. Overview of the procedure
5. Step 1 : Create the backup script
The script is too long to be included in this procedure. Please follow this link to see the script.
NOTE that you will have to make several corrections when using the script in pre-OpenSlug-2.7 environment. Up until OpenSlug-2.7, various system utilities were placed in `/opt/bin` directory. OpenSlug-2.7 probably changes this standard and places them (more appropriately) in `/usr/bin`. Therefore make sure that you change `/usr/bin` to `/opt/bin` in the backup script if you want to use it in OpenSlug-2.6 or earlier distributions.
Constants you are likely to change
Constants you are not likely to change
Script usageWith no parametersbackup.sh The script will describe shortly how to use this script. With 1 parameter backup.sh DailyBackups?
The first parameters is the name of a file that contains the directory to backup (see Step 2 : Create the configuration file to specify which directories to backup). With 3 parameters (mainly for debugging purposes)backup.sh /home/Outlook Outlook 12 The 3 parameters are exactly equivalent to one line in the previous config file (see Step 2 : Create the configuration file to specify which directories to backup) :
6. Step 2 : Create the configuration file to specify which directories to backupOne configuration file for a given backup frequencyYou must now create one config file for a given backup frequency. For example, if you want to backup daily some directories, weekly others, and montly some others, you have to create 3 config files : The first file will contains all directories to backup daily. I propose to create them in /home/scripts (the same directory that contains backup.sh). The syntax of the configuration fileWhatever the file, the syntax is the same. A configuration file is a set of lines.
Here is an example of DailyBackups? : /home/Users Users 365 Here is an example of WeeklyBackups? : /home/Outlook Outlook 52 /home/Mp3 Mp3 52 /home/Photos Photos 52 Here is an example of MonthyBackups? : /home/Utl Utl 12 /home/Backup Backup 12 /etc Etc 12 /home/scripts Scripts 12 7. Step 3 : Add cron jobs to schedule the backupsCreate the crontab file
0 4 1 * * /home/scripts/backup.sh /home/scripts/MonthlyBackups | nail -s "Monthly backup status" myemail@myisp.fr 0 4 1 * * /home/scripts/backup.sh /home/scripts/WeeklyBackups | nail -s "Weekly backup status" myemail@myisp.fr 0 4 * * * /home/scripts/backup.sh /home/scripts/DailyBackups | nail -s "Daily backup status" myemail@myisp.fr
Add a script to load correctly the crontab file at startupThe issue is that the /etc/crontab file will not be correctly loaded at startup.
#! /bin/bash
# load the relevant cron file
BIN_CRONTAB="/usr/bin/crontab";
CFG_CRONTAB="/etc/crontab";
OK=0;
KO=1;
if [ ! -e "$BIN_CRONTAB" ]; then
{
echo "Missing $BIN_CRONTAB";
exit $KO;
}
elif [ ! -e "$CFG_CRONTAB" ]; then
{
echo "Missing $CFG_CRONTAB";
exit $KO;
}
else
{
$BIN_CRONTAB -u root $CFG_CRONTAB;
$BIN_CRONTAB -l
}
fi;
exit $OK;
ln -s /etc/init.d/_configure_cron.sh /etc/rcS.d/S99configure_cron.sh 8. Step 4 : Configure the mail sending
Therefore, type the following :
ln -s /usr/sbin/sendmail /usr/lib/sendmail
# # /etc/ssmtp.conf -- a config file for sSMTP sendmail. # # The person who gets all mail for userids < 1000 root=root # The place where the mail goes. The actual machine name is required # no MX records are consulted. Commonly mailhosts are named mail.domain.com # The example will fit if you are in domain.com and you mailhub is so named. mailhub=smtp.myisp.fr # Where will the mail seem to come from? #rewriteDomain=localhost.localdomain # The full hostname hostname=myisp.fr
8. Step 5 : Reboot and check that everything is okReboot the slungsync reboot Check cron jobscrontab -l Check the scripts cd /home/scripts
backup.sh DailyBackups?
If necessary, check the backup.sh scriptcd /home/scripts backup.sh /home/Outlook Outlook 12 |