Rewritten main function to be as general as it can be
This commit is contained in:
parent
30b4a2716f
commit
e5a90c6df0
@ -3,24 +3,39 @@
|
|||||||
if [ $# -ne 1 ]; then
|
if [ $# -ne 1 ]; then
|
||||||
printf "createarchive\n"
|
printf "createarchive\n"
|
||||||
printf "usage: createarchive <folder to be archived>\n"
|
printf "usage: createarchive <folder to be archived>\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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# what this does in short: tar, compress, timestamp, shred the tar, mv .xz to pwd and display it
|
# 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
|
doathing() {
|
||||||
|
cd $basedir/..
|
||||||
thisfunc() {
|
tar cfv "$tmpdir/$g" "$f" && \
|
||||||
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
|
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 [ ! -d $1 ]; then
|
||||||
if [ `echo $?` -eq 0 ]; then
|
echo "$1 is not a directory"
|
||||||
printf "done\n"
|
exit 1
|
||||||
exit 0
|
|
||||||
else
|
else
|
||||||
printf "there were some errors\n"
|
echo `pwd`
|
||||||
exit 1
|
echo "$f"
|
||||||
|
echo "$1"
|
||||||
|
|
||||||
|
doathing
|
||||||
|
trap "rm -rfv $tmpdir" 0 1 3 15
|
||||||
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user