-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.sh
31 lines (25 loc) · 1.24 KB
/
backup.sh
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
#! /bin/bash
cat <<EOF > $HOME/Documents/scripts/backup.sh
#! /bin/bash
# A simple script that makes incremental backups using rsync
# This script should be run using sudo if you plan to backup system-wide folders
# Requests the backup source and its destination
read -p 'Please, input the backup source: ' SOURCE
echo
read -p 'Please, input the backup destination: ' DESTINATION
echo
echo The backup source is $SOURCE and its destination is $DESTINATION
echo
# Checks if the user wants to remove destination files do not matching the source
read -p 'Type YES to delete the destination folder files that do not match the source: ' DELETE
echo
grep -q YES <<< $DELETE && sudo rsync -aAXv --delete --checksum --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","swapfile","lost+found","ecryptfs","$HOME/.cache/*","$HOME/.mozilla/*"} $SOURCE $DESTINATION ||sudo rsync -aAXv --checksum --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","swapfile","lost+found","ecryptfs","$HOME/.cache/*","$HOME/.mozilla/*"} $SOURCE $DESTINATION
echo
echo Done
EOF
SCRIPT_LOCATION=$HOME/Documents/scripts/backup.sh
chmod +x $SCRIPT_LOCATION
cat <<EOF > /etc/cron.daily/backup
#! /bin/bash
00 22 * * * $SCRIPT_LOCATION
EOF