BACKUP_SCRIPTS VERSION 1.0 This collection of bash shell scripts are meant to backup certain directories to the separate partition (directory) or remote backup server. Full backup will be run every month at 28.th day and incremental backups will be run every day. Incremental backups are maintained weekly as a separate files. This means that there is four to about nine weeks time schedule for the file recovery. The backup_scripts version 1.0 was tested with RedHat 9. However other UNIX platforms should be fine if the code is modified. DAILY BACKUPS Daily backup shell script is called backup_daily.sh. Daily backups are kept in the separate directory (variable's $daily default is /mnt/backup/daily). Modification time of the file date.lock defines what files to be backed up. Variable $dirs defines what directories to be backed up. The default is "/home /root". Daily incremental backup files are named .backup.tar.gz. List of files in the daily backups are maintained separately. List of files are named .backup.tar.gz.txt. File errors.txt holds errors that occurred during last backup procedure. Content of daily backup directory will look like this (on sunday before weekly backup script is run): date.lock errors.txt Mon.backup.tar.gz.txt Mon.backup.tar.gz Tue.backup.tar.gz.txt Tue.backup.tar.gz Wed.backup.tar.gz.txt Wed.backup.tar.gz Thu.backup.tar.gz.txt Thu.backup.tar.gz Fri.backup.tar.gz.txt Fri.backup.tar.gz Sat.backup.tar.gz.txt Sat.backup.tar.gz Sun.backup.tar.gz.txt Sun.backup.tar.gz If any errors occurred during daily backup procedure a mail message is sent to the root. WEEKLY BACKUPS Weekly backup shell script is called backup_weekly.sh. Weekly backups are kept in the separate directory (variable's $weekly default is /mnt/backup/weekly). Weekly backup files are named ..backup.tar. Weekly backup will be run every week on sunday. Contents of weekly backups are the files that appeared in the daily backup directory i.e. one weekly backup file contains daily incremental backups. File errors.txt holds errors that occurred during last backup procedure. Typical content of weekly backup directory will look like this (before October's monthly backup script is run): errors.txt 36.Sep.backup.tar 37.Sep.backup.tar 38.Sep.backup.tar 39.Sep.backup.tar 40.Oct.backup.tar 41.Oct.backup.tar 42.Oct.backup.tar 43.Oct.backup.tar If any errors occurred during weekly backup procedure a mail message is sent to the root. MONTHLY BACKUPS Monthly backup shell script is called backup_monthly.sh. Monthly backups are kept in the separate directory (variables $monthly default is /mnt/backup/monthly). Variable $dirs defines what directories to be backed up. The default is "/home /root". Monthly full backup files are named .backup.tar.gz. Monthly full backups will be run every month at 28.th day. List of files in the monthly backups are maintained separately. List of files are named .backup.tar.gz.txt. File errors.txt holds errors that occurred during last backup procedure. Typical content of monthly backup directory will look like this (before October's monthly backup script is run): errors.txt Sep.backup.tar.gz Sep.backup.tar.gz.txt If any errors occurred during monthly backup procedure a mail message is sent to the root. After monthly backup have been successfully run previous month's full backup and weekly incremental backups will be removed. For example after October's monthly backup is run, the monthly backup directory will look like this: errors.txt Oct.backup.tar.gz Oct.backup.tar.gz.txt And the weekly backup directory will look like this: errors.txt 40.Oct.backup.tar 41.Oct.backup.tar 42.Oct.backup.tar 43.Oct.backup.tar This means that there is four to about nine weeks time schedule for the file recovery. CRON AND ANACRON The backup_scripts should be run as a cron job so that backup_daily.sh will be run every day before backup_weekly.sh, backup_weekly.sh will be run every week on sunday before backup_monthly.sh and backup_monthly.sh will be run every month at 28.th day. An example of cron job configuration file is given in the file called backups. Copy this file to the /etc/cron.d and modify times as needed. However if the computer is not always on (for example the computer is a workstation), the backup_scripts could be run as a anacron job. An example of anacron job configuration file is given in the file anacrontab. Insert these configurations to the /etc/anacrontab and modify times as needed. INSTALLATION (RedHat 9) 1) Log in as a root 2) Create backup directory $ mkdir /mnt/backup [ Option: Mount backup directory from the remote backup computer Insert following line to the /etc/fstab backup.localdomain:/opt/backup /mnt/backup nfs rsize=8192,wsize=8192,timeo=14,intr where backup.localdomain is you own NFS server and /opt/backup is a remote NFS share. Mount remote backup directory to the local backup directory: $ mount /mnt/backup ] 3) Create daily, weekly and monthly backup directories $ mkdir /mnt/backup/daily $ mkdir /mnt/backup/weekly $ mkdir /mnt/backup/monthly 4) Create file date.lock for the incremental backups to the daily backup directory $ touch /mnt/backup/daily/date.lock 5) Create backup_scripts directory $ mkdir /opt/backup_scripts 6) Unpack backup_scripts_1_0.tar to the backup_scripts directory $ mv backup_scripts_1_0.tar /opt/backup_scripts $ cd /opt/backup_scripts $ tar -xvf backup_scripts_1_0.tar 7) Change backup_scripts shell file owner and permissions $ chown root:root /opt/backup_scripts/* $ chmod 700 /opt/backup_scripts/*.sh 8) Modify /opt/backup_scripts/*.sh shell files as needed Modify variable $dirs as needed i.e. insert directories you would like to backup to this variable. The default is "/home /root". 9) Make backup_scripts run as a cron or anacron job For the Server: $ cp /opt/backup_scripts/backups /etc/cron.d For the Workstation: Insert appropriate lines from /opt/backup_scripts/anacrontab to the /etc/anacrontab Modify running times of /etc/cron.d/backups or /etc/anacrontab as needed. 10) Backup_scripts is now ready to run, test the installation ---------------------------------------------------------------------------- The backup_scripts is copyright (c) by Mika Panhelainen (alias mpan) 2003 ALL RIGHTS RESERVED. WE DO NOT GIVE WARRANTY OF ANY KIND. USE YOUR OWN RISK. Distribution and modification of this program is highly allowed. However the original copyright holder should be mentioned. Best regards, Mika Panhelainen (genii@hushmail.com) ---------------------------------------------------------------------------- VERSION HISTORY v1.0, 10/2003: - First release version - Automatic previous monthly full backup removal added - /bin/sh changed to the /bin/bash for the clarity - Spell checked v0.9, 9/2003: - Version numbering added - Error message sending to the root added - Published in the news groups sfnet.atk.linux.palvelimet and sfnet.tietoliikenne.palvelimet vUNNUMBERED, 9/2003 - Published in the news groups sfnet.atk.linux.palvelimet and sfnet.tietoliikenne.palvelimet vINITIAL, 9/2003 - Initial version - Made as a voluntary work to the Kotikartanoyhdistys ry