Differences
This shows you the differences between two versions of the page.
linux_wiki:rsync_backup_script [2015/04/12 23:46] billdozor |
linux_wiki:rsync_backup_script [2019/05/25 23:50] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Rsync Backup Script ====== | ||
- | **General Information** | ||
- | |||
- | 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. | ||
- | |||
- | **Checklist** | ||
- | * List of source folders to backup (/ | ||
- | * Storage mounted somewhere to backup to (/backups/ in this example) | ||
- | |||
- | ---- | ||
- | |||
- | ===== The Script ===== | ||
- | |||
- | <code bash 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 ==== | ||
- | 1) Edit your crontab: | ||
- | <code bash> | ||
- | crontab -e | ||
- | </ | ||
- | |||
- | 2) Schedule the script to be run every night at 11:00pm (for example) | ||
- | <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 * * * / | ||
- | </ |