Bash system backup script help
Hello all,
I'm looking for someone with a little more experience in scripting than I have to look over this script and confirm that it will do what I expect. It is for backing up my system Code:
#! /bin/bash Any edits and/or suggestions appreciated! |
After thinking about it some more, I'm thinking the destination directory should be written as just "$_", and I can drop the "v" option to rsync since it's a script
|
It wouldn't hurt to just run it and see what happens. It looks all right, but here are a few minor suggestions:
Rather than test whether /media/3tb is mounted, you could test whether /media/3tb/.sysbak exists. You could use newlines instead of semicolons. It's more readable, or am I missing the reason for semicolons? You don't need the mkdir. You can get rsync to create the directory with: Code:
rsync -aAX --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home"} / /media/3tb/.sysbak/$(date +'%d%b%Y') You don't need the else block, unless you plan to add functionality there later. When backing up a live system, rsync is likely to generate non-fatal error messages as files are modified or deleted while rsync is running. Redirect stderr to a logfile if you want to examine the error messages, or to /dev/null if you want to ignore them. If you plan to back up often, consider using the rsync --link-dest option. It will save a lot of disk space by using hardlinks instead of duplicating unchanged files. It requires a destination filesystem which supports hardlinks. For optimum efficiency of disk space, the script would need to identify the most recent backup which ran to completion (that is, which was not interrupted), and use that as the --link-dest directory. |
Perhaps you want to ensure that the mkdir was successful then you can chain the next command with a &&
Code:
if grep -qs '/media/3tb' /proc/mounts; then rsync creates many files. If you want to keep several backups then tar or cpio or dump archives would be more efficient. |
All times are GMT -5. The time now is 09:11 PM. |