-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_backup.sh
executable file
·51 lines (44 loc) · 1.95 KB
/
do_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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# backup of directory BACKUPS on server
source ~/bin/secrets
# NOTE: put directories without the ending "/"
declare locale="${backup_locale_dir}"
declare remote="${backup_remote_dir}"
declare pass_file
#declare opts=`getopt -n $0 -o hc -l help,complete -- $@`
set -e
if [ $# -gt 2 -o "$1" = "-h" -o "$1" = "--help" ]; then
echo options:
echo -e "-h --help\tprint this text and exit"
echo -e "-c --complete\tsyncronize completely with this machine\n\t(delete files on server that doesn't exist here)"
echo the default behaviour is to upload modifications and then download new files added to the server
exit
fi
pass_file=`mktemp --tmpdir`
echo -e "backup of\n $locale\n\t<<< >>>\n $remote\n\n"
read -s -p "insert password for \"$remote\": " pass
echo "$pass" > "$pass_file"
unset pass
if [ "$1" = "-c" -o "$1" = "--complete" ]; then
echo -e "\nlist of files that WILL be deleted:"
sleep 3
rsync --dry-run --info=DEL --password-file "$pass_file" --delete -urOt "$locale"/ "$remote" |cut -d ' ' -f 2-
echo -e "\nWARNING: these files will be DELETED from the server! continue? [y/N]"
read ans
if [ "$ans" = y -o "$ans" = yes ]; then
rsync --password-file "$pass_file" --delete --delete-delay -vurOt "$locale"/ "$remote"
else
echo aborting...
fi
else
echo -e "\n\tLOCALHOST-SERVER SYNC\n"
# NOTE: -t is used to preserve modification timestamps
# NOTE: -o doesn't use -t for directories (if not used, timestamps are updated for directories everytime)
# if --size-only isn't used on the second sync for some reason the download may include all files present on the server
# NOTE: -F skyps files that match the filters specified in .rsync-filter
rsync --password-file "$pass_file" -vurOtF --modify-window=1 "$locale"/ "$remote"
echo -e "\n\tSERVER-LOCALHOST SYNC\n"
#rsync --password-file "$pass_file" -vurOtF --modify-window=1 --size-only "$remote"/ "$locale"
rsync --password-file "$pass_file" -vurOtF --modify-window=1 "$remote"/ "$locale"
fi
rm $pass_file