summaryrefslogtreecommitdiff
path: root/kyanite.sh
diff options
context:
space:
mode:
authorDerek Stevens <nilix@nilfm.cc>2020-08-31 09:59:21 -0400
committerDerek Stevens <nilix@nilfm.cc>2020-08-31 09:59:21 -0400
commitb0202a3c4825305350a9b5308026bf6ad65e7bb0 (patch)
tree6f04c4a413292abcde83c8138130b274adbb485f /kyanite.sh
Initial commit
Diffstat (limited to 'kyanite.sh')
-rwxr-xr-xkyanite.sh62
1 files changed, 62 insertions, 0 deletions
diff --git a/kyanite.sh b/kyanite.sh
new file mode 100755
index 0000000..672b15d
--- /dev/null
+++ b/kyanite.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+helpme() {
+ echo "usage:"
+ echo " kyanite.sh full|partial|restore SRC DEST [options]"
+ echo " COMMANDS:"
+ echo " full: make a full backup of SRC to DEST/HOST/TIMESTAMP_full/"
+ echo " this can be a remote path in user@host:path form too"
+ echo " partial: make partial backup of SRC to DEST/HOST/TIMESTAMP_part/"
+ echo " relative to the latest full backup in that directory"
+ echo " restore: restore the backup at DEST/ to SRC/"
+ echo " OPTIONS:"
+ echo " anything provided after DEST is passed as additional options to rsync,"
+ echo " e.g. '--exclude .cache'"
+}
+
+if [ -z "$3" ]; then
+ helpme;
+ exit;
+fi
+
+if [ "$1" = "full" ]; then
+ mode=full;
+elif [ "$1" = "partial" ]; then
+ mode=part;
+elif [ "$1" = "restore" ]; then
+ mode=restore;
+else mode=none;
+fi
+shift;
+
+srcDir=$1;
+shift;
+
+destDir=$1
+remoteHost=$(echo $destDir | awk -F : '{ print $1 }' | awk -F @ '{ print $2 }');
+
+if [ ! -z "${remoteHost}" ]; then
+ host=${remoteHost};
+else host=$(hostname)
+fi
+shift;
+
+case $mode in
+ full)
+ fullDest=${destDir}/${host}/$(date +%Y-%m-%d_%H:%M)_full;
+ mkdir -p ${fullDest};
+ rsync -av $@ ${srcDir} ${fullDest};
+ ;;
+ part)
+ fullDest=${destDir}/${host}/$(date +%Y-%m-%d_%H:%M)_part;
+ lastFullBackup=$(ls -1 ${destDir}/$(hostname)/*_full | tail -n 1);
+ mkdir -p ${fullDest};
+ rsync -av --link-dest=${lastFullBackup} $@ ${srcDir} ${fullDest};
+ ;;
+ restore)
+ rsync -av $@ ${srcDir} ${destDir}
+ ;;
+ *)
+ helpme
+ ;;
+esac \ No newline at end of file