CloneX et CCC sont intéressants mais en fait ils utilisent des fonctionnalités parfaitement accessibles par des commandes shell...
Evidemment un script shell ne sera jamais aussi joli qu'une app Cocoa mais pour des backups de données c'est très suffisant, en plus vous pouvez attachez le script à un cron (man cron).
copier entre ---- DEBUT et ----- FIN dans un fichier par exemple darc.sh à mettre dans ~/bin, faire un chmod 755 ~/bin/darc.sh dans une fenêtre Terminal, et ensuite
~/bin/darc.sh Nom_du_dossier_à_sauvegarder
créera un Nom_du_dossier à sauvegarder.dmg.tgz, une image dmg du dossier compactée avec tar et gzip,
seule restriction pas d'espace dans le Nom_du_dossier_à_sauvegarder
(la restriction ne s'applique pas aux fichiers/dossiers inclus dans le dossier à sauvegarder)
le Nom_du_dossier_à_sauvegarder peut-être un fichier, il peut y avoir plusieurs noms... dans ce cas une archive par paramètre (voir aussi option -o)
différentes options
-r effacera le dmg intermédiaire
-R effacera le dmg ET l'original
-l listera le contenu du backup dans un .txt
-L listera le contenu du backup dans un .bom
(man mkbom)
-v travaille en mode "verbeux" (plus de message)
-o archive_file_name spécifie le nom e la dmg et si l'on pase plusieurs paramètres, ils seront TOUS dans cette archive unique
-h donne les explications (en anglais)
comme quoi en lisant les pages man on peut faire beaucoup de choses : man ditto mkbom lsbom hdiutil hdid grep awk sh test
Eviter quand même de faire un sudo darc.sh -R sur /bin /Library /usr /dev /etc /System / tout court etc.
----------- DEBUT ----------------
#! /bin/sh
# (c) P3 Consulting, 2002
# All rights Reserved
# LICENSE: GPL
# TODO
# 1. support of file names containing spaces
# 2. more testing to be better bullet proof
# 3. option -b to directly burn the archive
# 4. your suggestions mailto:
[email protected]
function echo_help
{
echo "Usage darc [-h|f|r|R|o archivefilename] file(s)..."
echo "-f to force if .dmg already exists"
echo "-r to remove temporaries"
echo "-R to remove temporaries AND original"
echo "-o archivefilename to output to one archive file"
echo "-h display this message"
echo "-v verbose mode"
echo "-l list saved files in a $arg.txt file (using ls -lR)"
echo "-L list saved files in a $arg.bom file (using mkbom) "
echo "(c) P3 Consulting
[email protected], GPL License"
}
args=`getopt lLvhfrRo: $*`
if test $# = 0
then
echo_help
exit 2
fi
set -- $args
for i in $*
do
case "$i"
in
-f)
force=$i; shift;;
-r|-R)
remove=$i; shift;;
-h)
help=$i; shift;;
-o)
only1=$i; oarg=$2; shift; shift;;
-v)
verbose=$i; shift;;
-l)
list=$i; shift;;
-L)
bom=$i; shift;;
--)
shift; break;;
esac
done
if test "$help" = "-h"
then
echo_help
exit 0
fi
if test "$only1" = "-o"
then
# we have to calculate the sum of all files
# we increase by 15% to take into account hfs formatting overhead, anyway gzip will compact unused space to almost 0
# maybe 10% would be enough
sum=`du -s $* | awk 'BEGIN{ s=0 }{ s +=$1 } END{ print s}' | awk '{ print $1*1.15 }' | awk 'BEGIN{ FS ="." } {print $1}'`
# min 5mb for hfs dmg's
if test $sum -lt 10240
then
sum=10240
fi
if test -e "$oarg"".dmg"
then
if test "$force" = "-f"
then
if test "$verbose" = "-v"
then
echo "old image already exist: deleting..."
fi
rm "$oarg"".dmg"
else
if test "$verbose" = "-v"
then
echo "old image already exist: aborting (use -f argument to force)..."
fi
exit 1
fi
fi
dmg="$oarg"".dmg"
if test "$verbose" = "-v"
then
echo "creating disk image " $dmg
fi
hdiutil create $dmg -ov -sectors $sum
hdid -nomount "$oarg"".dmg" | awk '{print NR"\t"$1}' > /tmp/darc.tmp
dev=`cat /tmp/darc.tmp | grep ^3 | awk '{print $2}' | awk 'BEGIN {FS="/"}{print $3}'`
disk=`cat /tmp/darc.tmp | grep ^1 | awk '{print $2}' | awk 'BEGIN {FS="/"}{print $3}'`
echo ""
if test "$verbose" = "-v"
then
echo "creating file system on device " $dmg
fi
newfs_hfs -v $oarg "/dev/r"$dev
hdiutil eject $disk
hdid $dmg
if test "$verbose" = "-v"
then
echo "backing up files on " $dmg
fi
for i in $*
do
if test -e "$i"
then
arg=`echo $i | awk 'BEGIN { FS = "/" } { print $1 }'`
if test -d $i
then
dir="$i"
mkdir "/Volumes/$oarg/$dir"
else
dir= ""
fi
if test "$verbose" = "-v"
then
echo "ditto -rsrcFork $arg /Volumes/$oarg/$dir"
fi
if ! ditto -rsrcFork $arg /Volumes/$oarg/$dir
then
if test "$verbose" = "-v"
then
echo "error during backup : aborting..."
fi
hdiutil eject $disk
exit 1
fi
else
if test "$verbose" = "-v"
then
echo "Warning " $i " not found !"
fi
fi
if test "$list" = "-l"
then
ls -lR "/Volumes/$oarg/$arg" > "$oarg.txt"
fi
if test "$bom" = "-L"
then
mkbom "/Volumes/$oarg/$arg" "$arg.bom"
fi
done
hdiutil eject $disk
if test "$verbose" = "-v"
then
echo "tar-ing disk image..."
fi
if ! tar -czf "$oarg.dmg.tgz" "$oarg.dmg"
then
if test "$verbose" = "-v"
then
echo "error during tar-ing : aborting..."
fi
exit 1
fi
if test ("$remove" = "-R") -o ("$remove" = "-r")
then
if test "$verbose" = "-v"
then
echo "removing temporary... $oarg.dmg"
fi
rm "$oarg.dmg"
if test "$remove" = "-R"
then
if test "$verbose" = "-v"
then
echo "removing originals..."
fi
for i in $*
do
if test -e "$i"
then
arg=`echo $i | awk 'BEGIN { FS = "/" } { print $1 }'`
if test -d "$arg"
then
rm -R "$arg"
else
rm "$arg"
fi
fi
done
fi
fi
else
for i in $*
do
if test -e "$i"
then
arg=`echo $i | awk 'BEGIN { FS = "/" } { print $1 }'`
# we increase by 15% to take into account hfs formatting overhead, anyway gzip will compact unused space to almost 0
# maybe 10% would be enough
sum=`du -s $arg | awk '{ print $1*1.15 }' | awk 'BEGIN{ FS ="." } { print $1}'`
# min 5mb for hfs dmg's
if test $sum -lt 10240
then
sum=10240
fi
if test -e "$arg"".dmg"
then
if test "$force" = "-f"
then
if test "$verbose" = "-v"
then
echo "old image already exist: deleting..."
fi
rm "$arg"".dmg"
else
if test "$verbose" = "-v"
then
echo "old image already exist: aborting (use -f argument to force)..."
fi
exit 1
fi
fi
dmg="$arg"".dmg"
if test "$verbose" = "-v"
then
echo "creating disk image " $dmg
fi
hdiutil create $dmg -ov -sectors $sum
hdid -nomount "$arg"".dmg" | awk '{print NR"\t"$1}' > /tmp/darc.tmp
dev=`cat /tmp/darc.tmp | grep ^3 | awk '{print $2}' | awk 'BEGIN {FS="/"}{print $3}'`
disk=`cat /tmp/darc.tmp | grep ^1 | awk '{print $2}' | awk 'BEGIN {FS="/"}{print $3}'`
echo ""
if test "$verbose" = "-v"
then
echo "creating file system on device " $dmg
fi
newfs_hfs -v $arg "/dev/r"$dev
hdiutil eject $disk
hdid $dmg
if test "$verbose" = "-v"
then
echo "backing up files on " $dmg
fi
if ! ditto -rsrcFork $arg /Volumes/$arg
then
if test "$verbose" = "-v"
then
echo "error during backup : aborting..."
fi
hdiutil eject $disk
exit 1
fi
if test "$list" = "-l"
then
ls -lR /Volumes/$arg/ > "$arg.txt"
fi
if test "$bom" = "-L"
then
mkbom /Volumes/$arg/ "$arg.bom"
fi
hdiutil eject $disk
echo "tar-ing disk image..."
if ! tar -czf "$arg.dmg.tgz" "$arg.dmg"
then
if test "$verbose" = "-v"
then
echo "error during tar-ing : aborting..."
fi
exit 1
fi
if test ("$remove" = "-R") -o ("$remove" = "-r")
then
if test "$verbose" = "-v"
then
echo "removing temporaries..."
fi
rm "$arg.dmg"
if test ("$remove" = "-R")
then
if test "$verbose" = "-v"
then
echo "removing original..."
fi
if test -d "$arg"
then
rm -R "$arg"
else
rm "$arg"
fi
fi
fi
else
if test "$verbose" = "-v"
then
echo $i " not found !"
fi
fi
done
fi
------------ FIN ----------------