-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackupwithtimestamp.sh
More file actions
executable file
·46 lines (32 loc) · 944 Bytes
/
backupwithtimestamp.sh
File metadata and controls
executable file
·46 lines (32 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#! /usr/bin/env bash
########################################################################
# HELP
usage() {
echo -e "Usage examples:\n"
echo -e "compress: `basename $0` archive_prefix somefile anotherfile directory/"
}
########################################################################
# INIT
if [[ "" == "`which zstd`" ]]; then
echo 'install zstd (zstandard compression)!'
exit 3
fi
########################################################################
# COMPRESS
mkarchive() {
cd .
# checkpoint is not supported on freebsd
#tar --checkpoint=1000 --checkpoint-action=dot
tar -cf - "$@" | \
zstd -T0 --long -o "${OUTPUTFILE}"
}
OUTPUTFILE="`pwd`/${1}_`date +%Y%m%d_%H%M%S`.tar.zstd"
########################################################################
# MAIN
if [ $# -lt 2 ] ; then
usage
exit 1
fi
shift
mkarchive "$@"
echo -e "To decompress, run: zstd -dc $OUTPUTFILE | tar -x -C outputdirectory/"