imthenachoman / nBackup

A simple Bash script for making local backups with different views.
MIT License
32 stars 4 forks source link

nBackup

A simple Bash script for making local backups with different views.

Why

Obviously there are a lot of backup solutions that already exist. None of them met my requirements or were far more complicated than I need. I am a fan of the KISS principle and feel backups shouldn't be complex because then recovery is complicated and you don't want complex when shit's hit the fan and you need to recover critical data urgently.

Features

How It Works

This script implements the ideas covered here and here. I won't go into the details here -- read the articles if you're curious, but at a high level, the script works by making rsync backups of your data, then using hard-links to identify different versions. By using hard-links you save on space by only saving new copies of files if they have changed.

How To Use It

  1. clone the repo: git clone https://github.com/imthenachoman/nBackup
  2. copy nBackup.includes somewhere and add the folders you do want backed up
  3. copy nBackup.excludes somewhere and add the folders you do not want backed up
  4. copy nBackup.conf to ~/.nBackup.conf and edit per your requirements
  5. make sure BACKUP_INCLUDES_FILE and BACKUP_EXCLUDES_FILE in ~/.nBackup.conf point to correct paths for #2 and #3
  6. secure the permissions for ~/.nBackup.conf:
    1. chmod 600 ~/.nBackup.conf
    2. chown $(whoami):$(whoami) ~/.nBackup.conf
  7. execute nBackup.sh

Example End Result

Assuming your source folder looks like so:

And you do the following:

  1. take a backup
  2. delete source/file 003, add source/file 004, take a backup
  3. modify source/file 002, add some new files to source/folder 100, take a backup

This is how your backup folder would look:

Notice how the files share a common inode. This is because, since the file(s) didn't change, they point to the same file. When a file changes, the old versions point to the original and the new version points to a new file. This saves a lot of space.

Note: The actual file/folders will include date/time stamp but I have removed the time for this example. You can customize the date/time format you want to use.