Differences
This shows you the differences between two versions of the page.
linux_wiki:rsync_backup_script [2014/11/24 22:34] billdozor |
linux_wiki:rsync_backup_script [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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 == | ||
- | |||
- | <code bash file backuphome.sh> | ||
- | #!/bin/bash | ||
- | |||
- | # Get Current Date/Time for syncLog' | ||
- | CURRENTDATE=`date +%m%d%y_%T` | ||
- | |||
- | # Backup Home folder (Exclude Backups, | ||
- | rsync -ahv --exclude-from=/ | ||
- | |||
- | # Look in ~/ | ||
- | # older than 7 days. Delete them. -ctime ignores fractional parts, | ||
- | # so +7 equates to files at least 8 days ago | ||
- | |||
- | find / | ||
- | </ | ||
- | |||
- | == Call Backup Script with Cron == | ||
- | Edit your crontab: | ||
- | <code bash> | ||
- | crontab -e | ||
- | </ | ||
- | |||
- | and schedule the script to be run every night at 11:00pm: | ||
- | <code bash> | ||
- | # minute (m), hour (h), day of month (dom), month (mon), | ||
- | # and day of week (dow) or use ' | ||
- | # m h dom mon dow | ||
- | |||
- | 0 23 * * * / | ||
- | </ |