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.
and
or or
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 yearsnBackup
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.
git clone https://github.com/imthenachoman/nBackup
nBackup.includes
somewhere and add the folders you do want backed upnBackup.excludes
somewhere and add the folders you do not want backed upnBackup.conf
to ~/.nBackup.conf
and edit per your requirementsBACKUP_INCLUDES_FILE
and BACKUP_EXCLUDES_FILE
in ~/.nBackup.conf
point to correct paths for #2 and #3~/.nBackup.conf
:
chmod 600 ~/.nBackup.conf
chown $(whoami):$(whoami) ~/.nBackup.conf
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:
source/file 003
, add source/file 004
, take a backupsource/file 002
, add some new files to source/folder 100
, take a backupThis is how your backup folder would look:
backup
20190101
-- first backup
source
file 001
(inode # 10)file 002
(inode # 20)file 003
(inode # 30)20190201
-- second backup; deleted source/file 003
and added source/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 to source/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.