Ceci est une ancienne révision du document !
dar est un utilitaire sous linux permettant de réaliser des sauvegardes simple avec quelques fonctions avancées comme :
Cette page décrit comment l'utiliser ponctuellement ou de manière automatisée.
Installer le paquet :
Voici le résultat de l'aide intégrée à dar.
# dar -h
usage: dar [ -c | -x | -d | -t | -l | -C | -+ ] [<path>/]<basename> [options...]
dar -h
dar -V
Commands are:
-c creates an archive
-x extracts files from the archive
-d compares the archive with the existing filesystem
-t tests the archive integrity
-l lists the contents of the archive
-C isolates the catalogue from an archive
-+ merge two archives / create a sub archive
-h displays this help information
-V displays version information
Common options:
-v verbose output
-q suppress final statistics report
-vs display skipped files
-R <path> filesystem root directory (current dir by default)
-X <mask> files to exclude from the operation (none by default)
-I <mask> files to include in the operation (all by default)
-P <path> subdirectory to exclude from the operation
-g <path> subdirectory to include in the operation
-[ <filename> filename contains a list of files to include
-] <path> filename contains a list of files to exclude
-n don't overwrite files
-w don't warn before overwriting files
-wa don't warn before overwriting and removing files
-b ring the terminal bell when user action is required
-O[ignore-owner | mtime | inode-type] do not consider user and group
ownership
-H [N] ignore shift in dates of an exact number of hours
-E <string> command to execute between slices
-F <string> same as -E but for the archive of reference
-u <mask> mask to ignore certain EA
-U <mask> mask to allow certain EA
-K <string> use <string> as key to encrypt/decrypt
-J <string> same as -K but it does concern the archive of reference
-# <integer> encryption block size
-* <integer> same as -# but for archive of reference
-B <filename> read options from given file
-N do not read ~/.darrc nor /etc/darrc configuration file
-e dry run, fake execution, nothing is produced
-Q suppress the initial warning when not launched from a tty
-aa do not try to preserve atime of file open for reading.
-ac do not try to preserve ctime (default behavior).
-am set ordered mode for all filters
-an the masks that follow are now case insensitive
-acase the masks that follow are now case sensitive
-ar set the following masks to be regex expressions
-ag set the following masks to be glob expressions
-j ask user what to do when memory is exhausted
Saving / Isolation / merging options (to use with -c, -C or -+):
-A [path/]<basename> archive to take as reference
-@ [path/]<basename> auxiliary archive of reference for merging
-$ <string> encryption key for auxiliary archive
-~ <string> command between slices of the auxiliary archive
-z [level] compress data in archive using gzip algorithm
-y [level] compress data in archive using bzip2 algorithm.
-s <integer> split the archive in several files of size <integer>
-S <integer> first file size (if different from following ones)
-aSI slice size suffixes k, M, T, G, etc. are power of 10
-abinary slice size suffixes k, M, T, G, etc. are power of 2
-p pauses before writing to a new file
-D excluded directories are stored as empty directories
-Z <mask> do not compress the matching filenames
-Y <mask> do only compress the matching filenames
-m <number> do not compress file smaller than <number>
--nodump do not backup, files having the nodump 'd' flag set
-G [path/]<basename> Do on-fly catalogue isolation of the resulting archive
-M stay in the same filesystem while scanning directories
-, ignore directories that follow the Directory Tagging
Standard
Restoring options (to use with -x) :
-k do not remove files destroyed since the reference backup
-r do not restore file older than those on filesystem
-f do not restore directory structure
Reading options (to use with -x, -d, -t, -l, -A)
-i <named pipe> pipe to use instead of std input to read data from dar_slave
-o <named pipe> pipe to use instead of std output to orders dar_slave
Listing options (to use with -l):
-T tree output format
-as only list files saved in the archive
Type "man dar" for more details and for all available options.
Commençons par un simple sauvegarde de /home :
dar -v -c home -R / -g home
Quelques détails des options :
Exemple d'exécution :
# dar -v -c home -R / -g home Adding file to archive: /home Adding file to archive: /home/matthieu Adding file to archive: /home/matthieu/.bashrc Adding file to archive: /home/matthieu/.bash_logout Adding file to archive: /home/matthieu/.profile .... .... Writing archive contents... -------------------------------------------- 56 inode(s) saved with 0 hard link(s) recorded 0 inode(s) changed at the moment of the backup 0 inode(s) not saved (no inode/file change) 0 inode(s) failed to save (filesystem error) 28 inode(s) ignored (excluded by filters) 0 inode(s) recorded as deleted from reference backup -------------------------------------------- Total number of inodes considered: 84 -------------------------------------------- EA saved for 0 inode(s) --------------------------------------------
Pour visualiser la sauvegarde, il faut utiliser l'option -l :
dar -l home
Exemple :
[data ][ EA ][compr] | permission | user | group | size | date | filename ----------------------+------------+-------+-------+-------+-------------------------------+------------ [Saved] [-----] drwxr-xr-x 0 root 0 Sun Mar 7 15:08:58 2010 home [Saved] [-----] drwxr-xr-x matthieu matthieu 0 Fri Mar 5 21:48:35 2010 home/matthieu [Saved] [ ] -rw-r--r-- matthieu matthieu 3116 Fri Mar 5 21:48:35 2010 home/matthieu/.bashrc [Saved] [ ] -rw-r--r-- matthieu matthieu 220 Fri Mar 5 21:48:35 2010 home/matthieu/.bash_logout [Saved] [ ] -rw-r--r-- matthieu matthieu 675 Fri Mar 5 21:48:35 2010 home/matthieu/.profile ...
#!/bin/sh
# Dar backup script
# Matthieu Bouthors
# http://www.bouthors.fr
# licence GPLv2
# location of files
config_dir=/home/scripts
# temporary file
run_file=archive_gandalf_running
# dar options (DCF format)
dar_options=gandalf.dcf
# file that save the last full backup
last_backup_file=last_dar
# destination folder
archive_dir=/data/backup
case "$1" in
full)
if [ -e "$config_dir/$run_file" ]
then
echo archive already running
exit 1
fi
touch "$config_dir/$run_file"
archive_file="full_`date +%Y%m%d_%H%M%S`"
echo $archive_file
/usr/bin/dar -c $archive_dir/$archive_file -B $config_dir/$dar_options
if [ $? -eq 0 ]
then
echo "$archive_dir/$archive_file" > $config_dir/$last_backup_file
rm -f "$config_dir/$run_file"
exit 0
fi
rm -f "$config_dir/$run_file"
exit $?
;;
inc)
if [ ! -e "$config_dir/$last_backup_file" ]
then
echo no previous dar
exit 1
fi
old_dar=`cat $config_dir/$last_backup_file`
echo reference dar : $old_dar
if [ ! -e "$old_dar.1.dar" ]
then
echo previous dar not found
exit 1
fi
if [ -e "$config_dir/$run_file" ]
then
echo archive already running
exit 1
fi
touch "$config_dir/$run_file"
archive_file="inc_`date +%Y%m%d_%H%M%S`"
echo $archive_file
/usr/bin/dar -c $archive_dir/$archive_file -A $old_dar -B $config_dir/$dar_options
if [ $? -eq 0 ]
then
rm -f "$config_dir/$run_file"
exit 0
fi
rm -f "$config_dir/$run_file"
exit $?
;;
kill)
killall dar
rm -f "$config_dir/$run_file"
exit 0
;;
*)
echo "option : full, inc"
exit 1
esac
exit 0
Voici un script permettant de supprimer les sauvegardes trop vielles
#!/bin/sh
# Dar cleanup script
# Matthieu Bouthors
# http://www.bouthors.fr
# licence GPLv2
#folder to watch :
watch_folder=/data/backup/
# delete inc files older than inc_keep days :
inc_keep=60
# delete full files older than full_keep days :
full_keep=180
now=`date +%s`
limit_keep=$(($now-($inc_keep*86400)))
for filename in `ls $watch_folder/inc*.dar`
do
find_date_text=`expr match $filename '.*/inc_\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)_'`
date_file=`date -d $find_date_text +%s`
if [ $date_file -lt $limit_keep ]
then
/bin/rm -vf $filename
fi
done
limit_keep=$(($now-($full_keep*86400)))
for filename in `ls $watch_folder/full*.dar`
do
find_date_text=`expr match $filename '.*/full_\([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\)_'`
date_file=`date -d $find_date_text +%s`
if [ $date_file -lt $limit_keep ]
then
/bin/rm -vf $filename
fi
done