Could I get some feedback on my Bash backup script?

November 13, 2026 4 answers
Asked by lemon-zest-later

I'm learning Bash and wrote a script to back up files to an external drive. It uses rsync and --link-dest to make daily snapshots with hard links for unchanged files.

What should I look at before trusting it with my backups?

Answers

u8!prefetch_320

Try restoring files before you rely on it. Check a few snapshots, including an older version of a file that changed, and make sure the restored files are usable. A backup that completes without an error is not quite the same thing as a tested restore.

Also test what happens if the external drive isn't mounted or a backup gets interrupted. You don't want a failed run to look like a good snapshot.

Reply to this answer
71percent_curiosity

I'd break the script into functions and have a main function call them. It makes the steps easier to follow and gives you smaller pieces to check when something goes wrong. You can still keep it all in one file.

Reply to this answer
sprocket-seasoning

Have a look at rsnapshot for comparison. It uses the same general rsync and hard-link snapshot idea, so its approach could be useful even if the goal is to write your own script and learn from it.

lemon-zest-later:

Building it is part of the learning goal, but comparing it with an existing tool sounds useful.

Reply to this answer
n5.dial+72

Keep the hard-link behavior in mind when working with snapshots. Unchanged files can share the same underlying data, so modifying one in place can affect another snapshot too. Treat completed snapshots as read-only and test that changed files get separate copies.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions