Skip to main content
100%

Borg Backup Script

✓ Published0🌍 Public
Aadewes
Last edited Oct 3, 2017
Created on Aug 24, 2017

This example visualizes the backup decision logic of a Borg backup helper script, showing the time elapsed since the last backup and whether a new backup is due. It calculates the interval using shell commands and date arithmetic, comparing hours elapsed against a 24-hour threshold. The script uses the `stat` command to read the modification timestamp from `last_backup.txt`, `expr` for arithmetic, and the Borg CLI with `borg create` to perform the backup, including exclusions for patterns like `**/node_modules`. The visualization relies on the script’s output, echoing days and hours since the last backup.

AI-generated description

Borg Backup Script

This is a little helper script to regulary back up your data using the Borg backup tool. I wrote this as I was frustrated with Deja-Dup, which does not allow me to exclude directories by pattern, hence I ended up with backups that were very large and took a really long time to create because they contained many directories with non-essential files (e.g. node modules or Python virtual environments). Borg backup is a simple tool that offers everything that Deja-Dup does and is easier to customize.

  • Put the script in your home folder and make it executable.
  • Call it regularly using e.g. cron (put e.g. "0 * * * * [your username] /home/[your username]/make_backup.sh" in your /etc/crontab - this will call the script every hour). Please note that the script will perform its own checking to see if a new backup is necessary, so it doesn't hurt to call it very often. If you would put a specific date in crontab and it would happen that your computer is turned off at that date, crontab would not execute the backup script. By calling the script every hour we make sure that the backups are created regularly.
  • Modify the arguments that you pass to the Borg CLI to customize the directories that you want to back up.

The script will check the modification date of a file called last_backup.txt in your home directory to decide if a new backup should be created (by default once a week). If the file does not exist it will create it, if the backup fails it will erase it.

Similar vizzes