Using dar would be much easier if you did not have to memorize and specify all the flags and
the right syntax on the command line. In the script dar.sh we provide several Bash functions for easy backup. Please
note that these functions assume that you are below your quota (so you can write files!), have read and write
permissions, i.e. all the common-sense assumptions. It is your job to ensure that this is the case, and that dar
archived/restored your files correctly before you delete the originals. In other words, please test everything before
including these functions into your workflow.
Paste the function multidar() into your shell, or save its definition into your $HOME/.bashrc file and then enable it
with source ~/.bashrc.
Now, running the command without arguments will show you the syntax:
$ multidar
Usage: multidar sourceDirectory maxNumberOfFilesPerArchiveLet's assume that we have 1000 files inside test. Running the command
$ multidar test 300will produce four archives, each with its own basename and no more than 300 files inside. To restore from these archives, use a Bash loop:
$ for f in test-aa{a..d}
do
dar -R restore/ -O -w -x $f
doneThe function backup() provides an easy way to back up your directories. You need to define the four variables at the top:
BREFstores the absolute path of the parent directory (containing all subdirectories and files to archive)BSRCstores a relative (to BREF) list of subdirectories and files to archive; BSRC cannot be an absolute pathBDESTis the backup destinationBTAGwill form the root of the backup basename
To create the full backup all0.*.dar, type
$ backup 0To create the first incremental backup all1.*.dar, type
$ backup 1To create the second incremental backup all2.*.dar, type
$ backup 2and so on. To see all backups, type
$ backup showIf your current backup exceeds 5GB, more than one slice will be created.
If you have too many incremental backups, you can always create a lower-numbered backup, e.g.
$ backup 1will overwrite the first incremental backup and will remove all higher-numbered backups.
The function restore() will help you restore your backup. Similar to the previous function, you need to define these
variables:
BSRCis the backup directoryBTAGis the root of the backup basenameBDESTis the directory into which you are restoring
Search for a file test999 inside your backups with:
$ restore -l test999This will scan both the full backup and all incremental backups. To extract this file, you can specify the backup number and the full path of the file as it appears in the archive, e.g.
$ restore -n 2 test/test999However, this will not necessarily restore the file. This command will only restore the file if it was modified between backups 1 and 2 and therefore included into backup 2. To restore the file for sure, you have two options: either restore from the full backup and then from all incremental backups in the chronological order:
$ restore -n 0 test/test999
$ restore -n 1 test/test999
$ restore -n 2 test/test999
...or use the -x flag:
$ restore -x test/test999This last command will automatically go through all backups in the right order. To restore the entire directory, simply type:
$ restore -x testNote that restore() does not accept Unix wild masks.
To encrypt your backup, uncomment the line
#FLAGS+=(-K aes:) # add encryptionin backup() function. Then dar will ask for a separate password (and confirmation) for each new backup, and the
password for the reference (old) backup. When restoring, you will have to provide the password for each backup.