linux_wiki:rsync_backup_script

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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 (/home/bill/ in this example) 
-  * Storage mounted somewhere to backup to (/backups/ in this example) 
- 
----- 
- 
-===== The Script ===== 
- 
-<code bash 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 
-</code> 
- 
-==== Call Backup Script with Cron ==== 
-1) Edit your crontab: 
-<code bash> 
-crontab -e 
-</code> 
- 
-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 '*' in these fields (for 'any'). 
-# m h  dom mon dow   command 
- 
-0 23 * * * /home/bill/scripts/backuphome.sh 
-</code> 
  • linux_wiki/rsync_backup_script.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)