Linux backup script


This is very simple backup script with rsync.
This script take backup from remote location and stores locally (Central backup management).
Once the backup finished script notify to the user with time, date and amount of data transferred.

#!/bin/bash
emailaddress='user@example.com'
#setup local directory to store the backups
DIRECTORY=/srv/backups/
#set current date
DATE=`date '+%m-%d-%y%n'`
mkdir $DIRECTORY/$DATE
rsync --exclude-from '/tmp/exclude.txt' -avz user@remotehost.com:/tmp/backups/  $DIRECTORY/$DATE/ > /$DIRECTORY/$DATE/rsync.log
#the above line should be in a single line
tail -3 $DIRECTORY/$DATE/rsync.log |mail -s "Source Code Backup for example.com on $DATE" $emailaddress;

This script takes backup of all files and directories in /tmp/backups/ in remotehost.com
What happen if you don't want to backup some files and directories.
--exclude-from option specifies the list of files and folders to be excluded from backup.
Exclude file list can be in local host (For best practices Exclude list must be in local). In this Script I have stored exclude.txt in /tmp folder.

Sample Exclude list
somefilename.jpg
/log*
/test/test1/ab*
Download As PDF

No comments:

Post a Comment