dotfiles/backups/createarchive.sh

42 lines
1017 B
Bash
Raw Normal View History

2019-04-14 17:43:42 +02:00
#!/bin/bash
if [ $# -ne 1 ]; then
printf "createarchive\n"
printf "usage: createarchive <folder to be archived>\n"
printf "warning: the archive will be moved to "backups" directory (`echo $dest`)\n"
2019-04-14 17:43:42 +02:00
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
2019-04-14 17:43:42 +02:00
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"
2019-04-14 17:43:42 +02:00
}
if [ ! -d $1 ]; then
echo "$1 is not a directory"
exit 1
2019-04-14 17:43:42 +02:00
else
echo `pwd`
echo "$f"
echo "$1"
doathing
trap "rm -rfv $tmpdir" 0 1 3 15
exit $?
2019-04-14 17:43:42 +02:00
fi