Beginner Bash Backup Script: What Am I Missing?

0
1
Asked By MellowCedar42 On

I'm fairly new to programming and wrote a Bash script that backs up files to an external drive using rsync and --link-dest. It creates daily point-in-time directories that look like full copies, while unchanged files are hard-linked between backups to save space—similar to the directory-based approach used by tools such as rsnapshot.

I built it mainly to learn Bash and rsync, but I'd appreciate experienced eyes on the design, safety, portability, and edge cases. I'm especially interested in anything that could cause data loss or make the backups unreliable. The script also creates an incremental SHA-256 manifest for each backup so the files can be checked for silent corruption later without re-hashing everything during every run.

4 Answers

Answered By NorthStarLime7 On

The overall approach is reasonable, but the script would be easier to maintain if you organized it into functions and called a main function at the end. That keeps the execution flow clear and makes individual pieces easier to test. The Google Shell Style Guide is a useful reference for this style.

Answered By AmberKite31 On

There are established tools that use the same rsync-plus-hard-link design, such as rsnapshot. Your implementation is still worthwhile as a learning project, and the SHA-256 manifests are a useful addition for verifying old backups later. Just compare your script with mature tools to find edge cases you may not have considered.

Answered By QuietMaple88 On

Make sure temporary files are cleaned up with a trap rather than relying only on an rm command near the end. If the script is interrupted or exits early, the cleanup command may never run, leaving stale files behind. A trap can handle normal exits and signals more reliably.

Answered By SilverToast6 On

One terminology point: these are directory-based rsync snapshots, not filesystem snapshots in the LVM, Btrfs, VSS, or storage-array sense. Those systems provide copy-on-write behavior and can help create crash-consistent views of live data. It would be worth clarifying that distinction in the documentation so users know exactly what guarantees the script provides.

MellowCedar42 -

That’s fair. I’m using “snapshot” in the same directory-based sense as rsync and hard-link backup tools, but I’ll explain the distinction more clearly so it isn’t confused with filesystem-level snapshots.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.