A simple Bash script for making local backups with different views.
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.
- dependency-less - backups can be copied to a new system and restored without having to install a slew of programs/dependencies
- browsable in 3 ways - backups can be viewed/browsed in three different ways right from the command-line:
- current - the current version of the backup
- snapshot-in-time folders - if you want to view/restore all the data from a specific backup
- running file versions - if you want to quickly view previous versions of a specific file
- delete old backups - old backups can be deleted based on an
and
oror
combination of:count
- keep at least this many old backupsminimum age
- keep old backups that are newer than this many seconds, minutes, hours, days, weeks, months, or years
- e-mail status - status/output sent to e-mail
- speed over space - storage is cheap, processing time is not; there is no compression, tarring, or encryption (For my use-case, after
nBackup
takes a backup, I use https://rclone.org to send encrypted copies to my public cloud storage solution.)
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.
- clone the repo:
git clone https://github.com/imthenachoman/nBackup
- copy
nBackup.includes
somewhere and add the folders you do want backed up - copy
nBackup.excludes
somewhere and add the folders you do not want backed up - copy
nBackup.conf
to~/.nBackup.conf
and edit per your requirements - make sure
BACKUP_INCLUDES_FILE
andBACKUP_EXCLUDES_FILE
in~/.nBackup.conf
point to correct paths for #2 and #3 - secure the permissions for
~/.nBackup.conf
:chmod 600 ~/.nBackup.conf
chown $(whoami):$(whoami) ~/.nBackup.conf
- execute
nBackup.sh
Assuming your source folder looks like so:
source
file 001
(inode # 10)file 002
(inode # 20)file 003
(inode # 30)
And you do the following:
- take a backup
- delete
source/file 003
, addsource/file 004
, take a backup - modify
source/file 002
, add some new files tosource/folder 100
, take a backup
This is how your backup folder would look:
backup
20190101
-- first backupsource
file 001
(inode # 10)file 002
(inode # 20)file 003
(inode # 30)
20190201
-- second backup; deletedsource/file 003
and addedsource/file 004
source
file 001
(inode # 10)file 002
(inode # 20)file 004
(inode # 40)
20190301
-- third backup; modifiedsource/file 002
and added some new files tosource/folder 100
source
file 001
(inode # 10)file 002
(inode # 21) -- points to a different file than the previous backupsfile 004
folder 100
file 005
(inode # 50)file 006
(inode # 60)
current
source
file 001
(inode # 10)file 002
(inode # 21) -- points to the most recent version of the filefile 004
(inode # 40)folder 100
file 005
(inode # 50)file 006
(inode # 60)
combined
source
file 001.20190101
(inode # 10)file 002.20190101
(inode # 20)file 002.20190201
(inode # 21) -- notice there are two versions of this file in the same folder so you can quickly find the one you wantfile 003.20190101
(inode # 30)file 004.20190201
(inode # 40)folder 100
file 005.20190301
(inode # 50)file 006.20190301
(inode # 60)
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.