linux_wiki:rsync_backup_script

This is an old revision of the document!


Rsync Backup Script

This script backs up a home folder to a backup folder. It also creates a backup log, named after the timestamp that it runs. Lastly, it removes log files that were last modified more than 7 days ago.

backuphome.sh
file backuphome.sh
#!/bin/bash
 
# Get Current Date/Time for syncLog's name
CURRENTDATE=`date +%m%d%y_%T`
 
# Backup Home folder (Exclude Backups,NAS,Storage,USB)
rsync -ahv --exclude-from=/home/bill/excludes /home/bill /backups/ >> /home/bill/bin/rsync/syncLog_$CURRENTDATE 2>&1
 
# Look in ~/bin/rsync/ and find log files from rsync backups that are
#  older than 7 days.  Delete them. -ctime ignores fractional parts,
#  so +7 equates to files at least 8 days ago
 
find /home/bill/bin/rsync -name "syncLog_*" -type f -mtime +7 -delete
Call Backup Script with Cron

Edit your crontab:

crontab -e

and schedule the script to be run every night at 11:00pm:

# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# m h  dom mon dow   command
 
0 23 * * * /home/bill/scripts/backuphome.sh
  • linux_wiki/rsync_backup_script.1416886458.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)