add --name option and fix hostname part on lastFullBackup

This commit is contained in:
Iris Lightshard 2024-03-26 22:10:35 -06:00
parent 107851b42d
commit 178fec87b2
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3

View file

@ -2,12 +2,15 @@
helpme() { helpme() {
echo "usage:" echo "usage:"
echo " $0 full|partial|restore SRC DEST [options]" echo " $0 full|partial|restore [--name NAME] SRC DEST [options]"
echo " COMMANDS:" echo " COMMANDS:"
echo " full: Make a full backup of SRC to DEST/HOST/TIMESTAMP_full/" echo " full: Make a full backup of SRC to DEST/HOST/TIMESTAMP_full/"
echo " partial: Make partial backup of SRC to DEST/HOST/TIMESTAMP_part/" echo " partial: Make partial backup of SRC to DEST/HOST/TIMESTAMP_part/"
echo " relative to the latest full backup in that directory" echo " relative to the latest full backup in that directory"
echo " restore: Restore the backup at DEST/ to SRC/" echo " restore: Restore the backup at DEST/ to SRC/"
echo " NAME:"
echo " Force main subdir inside DEST instead of hostname."
echo " Useful if backing up, eg, external media."
echo " SRC:" echo " SRC:"
echo " Relative or absolute path for the source to backup or restore from." echo " Relative or absolute path for the source to backup or restore from."
echo " When backing up, can be a remote path in the form of user@host:path;" echo " When backing up, can be a remote path in the form of user@host:path;"
@ -37,6 +40,12 @@ else mode=none;
fi fi
shift; shift;
if [ "$1" = "--name" ]; then
shift
forcedName=$1;
shift;
fi
srcDir=$1; srcDir=$1;
shift; shift;
@ -45,8 +54,13 @@ remoteHost=$(echo $srcDir | awk -F : '{ print $1 }' | awk -F @ '{ print $2 }');
if [ ! -z "${remoteHost}" ]; then if [ ! -z "${remoteHost}" ]; then
host=${remoteHost}; host=${remoteHost};
else host=$(hostname) else host=$(hostname);
fi fi
if [ ! -z "${forcedName}" ]; then
host=${forcedName};
fi
shift; shift;
case $mode in case $mode in
@ -57,7 +71,7 @@ case $mode in
;; ;;
part) part)
fullDest=${destDir}/${host}/$(date +%Y-%m-%d_%H:%M)_part; fullDest=${destDir}/${host}/$(date +%Y-%m-%d_%H:%M)_part;
lastFullBackup=$(ls -1d ${destDir}/$(hostname)/*_full | tail -n 1); lastFullBackup=$(ls -1d ${destDir}/${host}/*_full | tail -n 1);
mkdir -p ${fullDest}; mkdir -p ${fullDest};
rsync -av --link-dest=${lastFullBackup} $@ ${srcDir} ${fullDest}; rsync -av --link-dest=${lastFullBackup} $@ ${srcDir} ${fullDest};
;; ;;