A script to do full, differential and incremental backups using `dar`. Some files are restored from the backups during verification, after which par2 redundancy files are created. The script also has a cleanup feature to remove old backups and par2 files.
Project description
Full, differential or incremental backups using 'dar'
The wonderful 'dar' [Disk Archiver] (https://github.com/Edrusb/DAR) is used for the heavy lifting, together with the par2 suite in these scripts.
My use case
I have cloud storage mounted on a directory within my home dir. The filesystem is FUSE based, which gives it a few special features
- a non-privileged user (me :-)) can perform a mount
- a privileged user cannot look into the filesystem --> a backup script running as root is not suitable
I needed the following:
- Backup my cloud storage to something local (cloud is convenient, but I want control over my backups)
- Backup primarily photos, video and different types of documents
- Have a simple non-complicated way of restoring, possibly years into the future. 'dar' fits that scenario with a single statically linked binary (kept with the archives). There is no need install/configure anything - restoring is simple and works well.
- During backup archives must be tested and a restore test (however small) performed
- Archives stored on a server with a reliable file system (easy to mount a directory over sshfs)
- Easy to verify archive's integrity, after being moved around.
I do not need the encryption features of dar, as all storage is already encrypted.
License
These scripts are licensed under the GPLv3 license. Read more here: https://www.gnu.org/licenses/gpl-3.0.en.html, or have a look at the "LICENSE" file in this repository.
Homepage - Github
This 'dar-backup' package lives at: https://github.com/per2jensen/dar-backup
This python version is v2 of dar-backup, the first is made in bash.
Config file
The default configuration is located here: ~/.config/dar-backup/dar-backup.conf
How to run
1
Config file default location is $HOME/.config/dar-backup/dar-backup.conf
The name of the file is the backup definition name.
Make as many backup definitions as you need. Run them all in one go, or run one at a time using the -d option.
Example:
[MISC]
LOGFILE_LOCATION=/home/user/dar-backup.log
MAX_SIZE_VERIFICATION_MB = 20
MIN_SIZE_VERIFICATION_MB = 1
NO_FILES_VERIFICATION = 5
[DIRECTORIES]
BACKUP_DIR = /home/user/mnt/dir/
BACKUP.D_DIR = /home/user/.config/dar-backup/backup.d/
TEST_RESTORE_DIR = /tmp/dar-backup/restore/
[AGE]
# age settings are in days
DIFF_AGE = 100
INCR_AGE = 40
[PAR2]
ERROR_CORRECTION_PERCENT = 5
[PREREQ]
SCRIPT_1 = /home/user/programmer/dar-backup/prereq/mount-microserver.sh
# SCRIPT_2 = <something>
# more here if necessary
2
Put your backup definitions in the directory $BACKUP.D_DIR (defined in the config file)
The dar documentation has good information on file selection.
Example of backup definition for a home directory
# Switch to ordered selection mode, which means that the following
# options will be considered top to bottom
-am
# Backup Root dir
-R /home/user
# Directories to backup below the Root dir
# if you only want to take a backup of /home/user/Documents
# -g Documents
# Directories to exclude below the Root dir
-P mnt
-P tmp
-P .cache
-P .config/Code/CachedData
-P .config/Code/Cache
-P ".config/Code/Service Worker"
-P .config/Code/logs
-P snap/firefox/common/.cache
-P git/darktable
# compression level
-z5
# no overwrite, if you rerun a backup, 'dar' halts and asks what to do
-n
# size of each slice in the archive
--slice 10G
# see https://github.com/per2jensen/dar-backup?tab=readme-ov-file#restore-test-exit-code-4
--comparison-field=ignore-owner
# bypass directores marked as cache directories
# http://dar.linux.free.fr/doc/Features.html
--cache-directory-tagging
3
Installation is currently in a venv. These commands are installed in the venv:
- dar-back
- cleanup
To install, create a venc and run pip:
mkdir $HOME/tmp
cd $HOME/tmp
python3 -m venv venv # create the virtual environment
. venv/bin/activate # activate the virtual env
pip install dar-backup # run pip to install `dar-backup`
I have an alias in ~/.bashrc
alias db=". ~/programmer/dar-backup.py/venv/bin/activate; dar-backup -v"
Typing db at the command line gives this
(venv) user@machine:~$ db
dar-backup alpha-0.4
dar-backup.py source code is here: https://github.com/per2jensen/dar-backup
Licensed under GNU GENERAL PUBLIC LICENSE v3, see the supplied file "LICENSE" for details.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See section 15 and section 16 in the supplied "LICENSE" file.
dar-backup -h gives the usage output:
(venv) user@machine:~$ dar-backup -h
usage: dar-backup [-h] [--full-backup] [--differential-backup] [--incremental-backup] [-d BACKUP_DEFINITION]
[--config-file CONFIG_FILE] [--examples] [--list] [--list-contents LIST_CONTENTS]
[--selection SELECTION] [--restore RESTORE] [--restore-dir RESTORE_DIR] [--verbose]
[--log-level LOG_LEVEL] [--do-not-compare] [--version]
Backup and verify using dar backup definitions.
options:
-h, --help show this help message and exit
--full-backup Perform a full backup.
--differential-backup
Perform differential backup.
--incremental-backup Perform incremental backup.
-d BACKUP_DEFINITION, --backup-definition BACKUP_DEFINITION
Specific 'recipe' to select directories and files.
--config-file CONFIG_FILE, -c CONFIG_FILE
Path to 'dar-backup.conf'
--examples Examples of using dar-backup.py.
--list List available archives.
--list-contents LIST_CONTENTS
List the contents of the specified archive.
--selection SELECTION
dar file selection for listing/restoring specific files/directories.
--restore RESTORE Restore specified archive.
--restore-dir RESTORE_DIR
Directory to restore files to.
--verbose Print various status messages to screen
--log-level LOG_LEVEL
`debug` or `trace`
--do-not-compare do not compare restores to file system
--version, -v Show version information.
4
You are ready to do backups of all your backup definitions, if your backup definitions are in place in BACKUP.D_DIR (see config file)
dar-backup --full-backup
or a backup of a single definition
dar-backup --full-backup -d <your backup definition>
5
Deactivate the virtual environment
deactivate
list contents of an archive
. <the virtual evn>/bin/activate
dar-backup --list-contents example --selection "-X '*.xmp' -I '*2024-06-16*' -g home/pj/tmp/LUT-play"
deactivate
gives
[Data ][D][ EA ][FSA][Compr][S]| Permission | User | Group | Size | Date | filename
--------------------------------+------------+-------+-------+---------+-------------------------------+------------
[Saved][-] [-L-][ 0%][ ] drwxr-xr-x root root 113 Mio Sat May 11 16:16:48 2024 home
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 10:46:30 2024 home/pj
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 09:17:42 2024 home/pj/tmp
[Saved][-] [-L-][ 1%][ ] drwxrwxr-x pj pj 50 Mio Wed Jun 19 20:52:13 2024 home/pj/tmp/LUT-play
[Saved][ ] [-L-][ 0%][X] -rw-rw-r-- pj pj 49 Mio Sun Jun 16 12:52:22 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15.NEF
dar file selection exmaples
select a directory
dar -l /tmp/example_FULL_2024-06-23 -g home/pj/tmp/LUT-play
gives
[Data ][D][ EA ][FSA][Compr][S]| Permission | User | Group | Size | Date | filename
--------------------------------+------------+-------+-------+---------+-------------------------------+------------
[Saved][-] [-L-][ 0%][ ] drwxr-xr-x root root 113 Mio Sat May 11 16:16:48 2024 home
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 10:46:30 2024 home/pj
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 09:17:42 2024 home/pj/tmp
[Saved][-] [-L-][ 1%][ ] drwxrwxr-x pj pj 50 Mio Wed Jun 19 20:52:13 2024 home/pj/tmp/LUT-play
[Saved][ ] [-L-][ 0%][X] -rw-rw-r-- pj pj 49 Mio Sun Jun 16 12:52:22 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15.NEF
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 48 kio Sat Jun 22 21:51:24 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 50 kio Sat Jun 22 21:51:25 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_01.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 51 kio Sat Jun 22 21:51:26 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_02.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 51 kio Sat Jun 22 21:51:27 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_03.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 51 kio Sat Jun 22 21:51:27 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_04.NEF.xmp
[Saved][ ] [-L-][ 97%][ ] -rw-rw-r-- pj pj 77 kio Sat Jun 22 21:50:16 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_05.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 52 kio Sat Jun 22 21:49:37 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_06.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:47 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_07.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:51:12 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_08.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:51:12 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_09.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:39 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_10.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:36 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_11.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:35 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_12.NEF.xmp
[Saved][ ] [-L-][ 88%][ ] -rw-rw-r-- pj pj 15 kio Sat Jun 22 21:51:11 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_13.NEF.xmp
[Saved][ ] [-L-][ 96%][ ] -rw-rw-r-- pj pj 84 kio Sat Jun 22 21:51:09 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_14.NEF.xmp
[Saved][ ] [-L-][ 96%][ ] -rw-rw-r-- pj pj 90 kio Sat Jun 22 21:51:04 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_15.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:51:15 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_16.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:48 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_17.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:19 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_18.NEF.xmp
select file dates in the directory:
dar -l /tmp/example_FULL_2024-06-23 -I '*2024-06-16*' -g home/pj/tmp/LUT-play
gives
[Data ][D][ EA ][FSA][Compr][S]| Permission | User | Group | Size | Date | filename
--------------------------------+------------+-------+-------+---------+-------------------------------+------------
[Saved][-] [-L-][ 0%][ ] drwxr-xr-x root root 113 Mio Sat May 11 16:16:48 2024 home
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 10:46:30 2024 home/pj
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 09:17:42 2024 home/pj/tmp
[Saved][-] [-L-][ 1%][ ] drwxrwxr-x pj pj 50 Mio Wed Jun 19 20:52:13 2024 home/pj/tmp/LUT-play
[Saved][ ] [-L-][ 0%][X] -rw-rw-r-- pj pj 49 Mio Sun Jun 16 12:52:22 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15.NEF
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 48 kio Sat Jun 22 21:51:24 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 50 kio Sat Jun 22 21:51:25 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_01.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 51 kio Sat Jun 22 21:51:26 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_02.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 51 kio Sat Jun 22 21:51:27 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_03.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 51 kio Sat Jun 22 21:51:27 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_04.NEF.xmp
[Saved][ ] [-L-][ 97%][ ] -rw-rw-r-- pj pj 77 kio Sat Jun 22 21:50:16 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_05.NEF.xmp
[Saved][ ] [-L-][ 95%][ ] -rw-rw-r-- pj pj 52 kio Sat Jun 22 21:49:37 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_06.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:47 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_07.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:51:12 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_08.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:51:12 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_09.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:39 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_10.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:36 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_11.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:35 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_12.NEF.xmp
[Saved][ ] [-L-][ 88%][ ] -rw-rw-r-- pj pj 15 kio Sat Jun 22 21:51:11 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_13.NEF.xmp
[Saved][ ] [-L-][ 96%][ ] -rw-rw-r-- pj pj 84 kio Sat Jun 22 21:51:09 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_14.NEF.xmp
[Saved][ ] [-L-][ 96%][ ] -rw-rw-r-- pj pj 90 kio Sat Jun 22 21:51:04 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_15.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:51:15 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_16.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:48 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_17.NEF.xmp
[Saved][ ] [-L-][ 92%][ ] -rw-rw-r-- pj pj 24 kio Sat Jun 22 21:50:19 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15_18.NEF.xmp
exclude .xmp files from that date
dar -l /tmp/example_FULL_2024-06-23 -X '*.xmp' -I '*2024-06-16*' -g home/pj/tmp/LUT-play
gives
[Data ][D][ EA ][FSA][Compr][S]| Permission | User | Group | Size | Date | filename
--------------------------------+------------+-------+-------+---------+-------------------------------+------------
[Saved][-] [-L-][ 0%][ ] drwxr-xr-x root root 113 Mio Sat May 11 16:16:48 2024 home
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 10:46:30 2024 home/pj
[Saved][-] [-L-][ 0%][ ] drwxrwxr-x pj pj 113 Mio Sun Jun 23 09:17:42 2024 home/pj/tmp
[Saved][-] [-L-][ 1%][ ] drwxrwxr-x pj pj 50 Mio Wed Jun 19 20:52:13 2024 home/pj/tmp/LUT-play
[Saved][ ] [-L-][ 0%][X] -rw-rw-r-- pj pj 49 Mio Sun Jun 16 12:52:22 2024 home/pj/tmp/LUT-play/2024-06-16_12:52:22,15.NEF
Nice :-)
Restoring
a single file
. <the virtual env>/bin/activate
# the path/to/file is relative to the Root when the backup was taken
dar-backup --restore <archive_name> --selection "-g path/to/file"
deactivate
.NEF from a specific date
. <the virtual env>/bin/activate
# the path/to/file is relative to the Root when the backup was taken
dar-backup --restore <archive_name> --selection "-X '*.xmp' -I '*2024-06-16*' -g home/pj/tmp/LUT-play"
deactivate
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dar_backup-0.5.8.tar.gz.
File metadata
- Download URL: dar_backup-0.5.8.tar.gz
- Upload date:
- Size: 26.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5dd9cd9869a49d25f1197f267a055f8888594df44cf312cb67b434256ecc254
|
|
| MD5 |
925a656195cf44b1479c0a47dbb2a920
|
|
| BLAKE2b-256 |
cafd3302a712ddaa447acf7815ec5b91caf396dd22b0bcf3f23e8bf07b8d4286
|
File details
Details for the file dar_backup-0.5.8-py3-none-any.whl.
File metadata
- Download URL: dar_backup-0.5.8-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8281cfd142e44188464d963b2b0f5d5a2d56319951f5b23969cf65578a9d93c
|
|
| MD5 |
3ea52e67fa999a09f889ae85800ab203
|
|
| BLAKE2b-256 |
31361807d76865e39a4201c0a5341cfa665b1e7b07038286d114b3abbc8ac19b
|