I have a lot of data that I’d hate to lose. Anyone with a hard drive failure really appreciates the value of having another copy of the lost data. I suppose cloud storage would be a logical place to backup data. With all my personal audio and video files, I might need as much as 10 TB of storage. That would be too expensive for me. My strategy has been to buy enough USB external hard drives to keep two copies of all my data. This has always been a manual process. I am working to automate my backup processes.
There are a couple of options when syncing two file directories. One is to simply copy all new files from the source to the target. Another is to additionally remove all the files from the target that have been removed from the source. I’ll automate the first procedure. If you accidentally remove all files from the source, the second procedure will also remove all files from the target. This option will only be used manually and very carefully.
Personal Documents
stub…
Audio, Video and Pictures
stub…
Duplicate Files
stub…
Server Backups
stub…
Rsync (ChatGPT)
I have three external USB drives: 4 TB, 5 TB, and 12 TB
You can use the following rsync command to synchronize the /documents directory from fileserver1 to fileserver2, ensuring that extra files on fileserver2 are removed:
rsync -av --delete fileserver1:/documents/ fileserver2:/documents/
Explanation of Options:
-a→ Archive mode (preserves permissions, timestamps, symbolic links, etc.).-v→ Verbose output (optional, shows progress).--delete→ Removes extra files onfileserver2that are not present onfileserver1.- The trailing
/after/documents/ensures correct directory syncing.
Additional Options (If Needed):
- Dry run before actual execution (to preview changes):
rsync -av --delete --dry-run fileserver1:/documents/ fileserver2:/documents/ - Use SSH for secure transfer (if servers are remote):
rsync -av --delete -e ssh fileserver1:/documents/ fileserver2:/documents/ - Limit bandwidth to avoid overloading network (e.g., limit to 5MB/s):
rsync -av --delete --bwlimit=5000 fileserver1:/documents/ fileserver2:/documents/
You can automate the rsync synchronization using a cron job.
Step 1: Edit the Crontab
On fileserver1, open the crontab editor:
crontab -e
Step 2: Add the Rsync Command
Add the following line to schedule synchronization every day at 2 AM:
0 2 * * * rsync -av --delete fileserver1:/documents/ fileserver2:/documents/ >> /var/log/rsync.log 2>&1
This will:
- Run
rsyncat 2:00 AM daily. - Log output to
/var/log/rsync.logfor debugging.
Step 3: Save and Exit
Save the file and exit the editor.
Step 4: Verify the Cron Job
After a day, check if the job ran:
cat /var/log/rsync.log
Would you like email notifications for failures?
Robocopy
stub…