-
Notifications
You must be signed in to change notification settings - Fork 2
/
backup-to-usb-disk-harm
executable file
·80 lines (69 loc) · 2.8 KB
/
backup-to-usb-disk-harm
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
72
73
74
75
76
77
78
79
80
#!/bin/bash
# backup-to-usb-disk
# makes a backup of some dirs to a usb disk if present
# starten kan met konsole --notoolbar --notabbar --nomenubar -T BACKUP --vt_sz 157x55 -e /data/scripts/backup-to-usb-disk
# Copyright (C) 2014-2015 Alexander Swen <alex@swen.nu>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Alexander Swen
# Private contact: alex@swen.nu
# CHANGELOG:
# 2009-05-27 A.Swen created.
# SETTINGS
date=$(date +%Y%m%d)
me=$(basename $0)
mydir=$(dirname $0)
dirs="/data/home/harm/Documents /data/mp3 /data/foto"
# FUNCTIONS
die () {
rc=$1
shift
echo "==========================">&2
echo "==== FATAL ERROR ====" >&2
echo "==========================">&2
echo "" >&2
echo $@ >&2
echo " "
echo "Er is iets mis!"
echo "Bel Alex en vertel hem de error die hierboven staat."
echo "druk op een enter om dit scherm te sluiten"
read whatever
exit $rc
}
do_sync () {
[ -z "${1}" ] && die 4 something went wrong. call alex
echo "backing up ${1}..."
echo " "
sudo /usr/bin/rsync -hrav --no-perms --no-owner --no-group "${1}" ${usb_disk}
echo " "
}
# SCRIPT
echo "Checking if disk is mounted..."
#[ "$(mount|grep "${usb_disk}")" = "" ] && die 1 usb disk ${usb_disk} not mounted.
# Er zijn twee bijna identieke schijven. ik werk met max 1 tegelijk
[ "$(sudo /sbin/blkid|awk '/400 GB HD/ {sub (/\:/, ""); print $1}'|wc -l)" == "1" ] || die 2 "Twee 400GB schijven aangetroffen. Ik weet niet waarheen ik moet schrijven"
disk=$(sudo /sbin/blkid|awk '/400 GB HD/ {sub (/\:/, ""); print $1}')
mp=$(mktemp -d)
sudo /bin/mount ${disk} ${mp}|| die 3 mount failed
[ -d "${mp}/pc/DOCUMENTEN $(date +%y-%m-%d)" ] || sudo /bin/mkdir -p "${mp}/pc/DOCUMENTEN $(date +%y-%m-%d)"
sudo /usr/bin/rsync -hrav --no-perms --no-owner --no-group "/data/home/harm/DOCUMENTEN/" "${mp}/pc/DOCUMENTEN $(date +%y-%m-%d)"
sudo /bin/umount ${mp}
[ -n "${mp}" -a -d "${mp}" ] && sudo /bin/rmdir ${mp}
echo " "
echo " "
echo "alles wat je hierboven ziet is gebackupped (plus alles wat al was gebackupped natuurlijk)"
echo "(er staan ook voor elke dir samenvattingen, als er geen files genoemd worden is er kennelijk"
echo "niets veranderd. niets om je zorgen over te maken dus)."
echo " "
echo "druk op een enter om dit scherm te sluiten"
read whatever
# END