-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup
More file actions
executable file
·71 lines (57 loc) · 2.38 KB
/
backup
File metadata and controls
executable file
·71 lines (57 loc) · 2.38 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#! /bin/bash
# TODO: Make sure aescrypt is installed BEFORE starting!!!!
# TODO: Exclude Microsoft and Slacks' shitty hidden cache
# .config/Microsoft/Microsoft Teams/Service Worker/CacheStorage/
# ./snap/slack/62/.config/Slack/Service Worker/CacheStorage
# TODO Use pigz to enable multithreaded compression.
# Update the restore file to do the same.
# gz: tar -I pigz -cf tarball.tgz files
# https://www.peterdavehello.org/2015/02/use-multi-threads-to-compress-files-when-taring-something/
# TODO Check the external media is available before starting.
# TODO Convert to python
# This first argument becomes part of the output filename.
# I used the words 'odd' for odd-numbered days, or 'even'
# or 'monthy' or 'quarterly', depending on when chron runs
# the backup job.
if [ -z "$1" ]
then
NAME="now"
else
NAME="$1"
fi
echo "Setting backup name to $NAME"
TAR_FILENAME="/tmp/backup-$NAME.tar.gz"
CHANGE_TO=/home/aaron
# BACKINGUP is a the directory (or file) relative to the CHANGE_TO
# directory that will be tarred, zipped, and encrypted (archived).
# When BACKINGUP is set to the dot '.' (current dir),
# an archive is created for the entire CHANGE_TO directory.
BACKINGUP=.
ENCRYPT_FILENAME="$TAR_FILENAME.aes"
EXT_FOLDER=/media/aaron/HOFFER_BACKUP
PASSWORD=$(cat /home/aaron/password)
# Save the scripts that handle the backup and restore.
mkdir -p "$EXT_FOLDER/scripts" && cp /home/aaron/.local/bin/{backup,restore} "$EXT_FOLDER/scripts"
echo "...Backing up $BACKINGUP to $TAR_FILENAME"
# The option "C" tells tar to change directory so the package content will be unpacked there
tar cz --verbose -C "$CHANGE_TO" -f "$TAR_FILENAME" --exclude='.m2/repository' --exclude='.cache' --exclude='.local/share/Trash' --exclude='VirtualBox VMs' "$BACKINGUP"
if [ $? -eq 2 ]; then
echo Tar command failed. Exiting now.
exit 1
fi
echo "...Created $(ls -sh "$TAR_FILENAME") ..."
echo "...Encrypting file as $ENCRYPT_FILENAME"
aescrypt -e -p $PASSWORD -o "$ENCRYPT_FILENAME" "$TAR_FILENAME"
if [ $? -ne 0 ]; then
echo Encryption failed. Exiting now.
exit 2
fi
#TODO Use rsync instead of copy because it is resumable.
# Change move to copy. It's nice to have the latest on the local drive in case an ext drive is not handy
echo "...Copy $ENCRYPT_FILENAME to $EXT_FOLDER"
cp -f "$ENCRYPT_FILENAME" "$EXT_FOLDER"
if [ $? -ne 0 ]; then
echo Could not move file to backup folder. Exiting now.
exit 3
fi
echo ...Done!