From e5a90c6df0520c6b01b6d76e82e4495865ed294f Mon Sep 17 00:00:00 2001 From: fedora Date: Thu, 27 Jun 2019 02:07:46 +0200 Subject: [PATCH] Rewritten main function to be as general as it can be --- backups/createarchive.sh | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/backups/createarchive.sh b/backups/createarchive.sh index 13d5cb3..4321eb6 100755 --- a/backups/createarchive.sh +++ b/backups/createarchive.sh @@ -3,24 +3,39 @@ if [ $# -ne 1 ]; then printf "createarchive\n" printf "usage: createarchive \n" - printf "warning: the archive will be moved to pwd (`pwd`)\n" + printf "warning: the archive will be moved to "backups" directory (`echo $dest`)\n" exit 1 fi # what this does in short: tar, compress, timestamp, shred the tar, mv .xz to pwd and display it +logdate="$(date +%Y%m%dT%H%M%S)" +basedir="$1" +tmpdir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXX") +#/run/user/$(id -u) tmpfs 0700 perms +f="`cd $basedir; pwd | tr '/' ' ' | sed 's/^.* / /' | cut -c2-`" > /dev/null +g="$logdate-$f.tar" +dest=~/MEGAsync/backups -f=$1 - -thisfunc() { -tar cfv $f.tar $f && xz -vzk9e $f.tar -S .`date +%Y%m%d%H%M%S`.xz && shred -zuv $f.tar && mv $f.tar.xz . && ls -latr | tail -1 +doathing() { + cd $basedir/.. + tar cfv "$tmpdir/$g" "$f" && \ + xz -vzk9e "$tmpdir/$g" -S .xz && \ + rsync -avP "$tmpdir/$g.xz" "$dest" && \ + shred -zuv "$tmpdir/$g" "$tmpdir/$g.xz" && \ + printf "\n" + ls -latr "$dest/$g.xz" } -thisfunc -if [ `echo $?` -eq 0 ]; then - printf "done\n" - exit 0 +if [ ! -d $1 ]; then + echo "$1 is not a directory" + exit 1 else - printf "there were some errors\n" - exit 1 + echo `pwd` + echo "$f" + echo "$1" + + doathing + trap "rm -rfv $tmpdir" 0 1 3 15 + exit $? fi