diff options
author | Mike Crute <mike@crute.us> | 2021-07-28 22:42:10 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2021-07-28 22:42:10 -0700 |
commit | 21a8cd5be238acd20b6196674d27d830f879fd0f (patch) | |
tree | a636df0f391da6c840f1959d491e17a253d2e684 | |
parent | 16f6d73fde01c02a5a4bfd5c0e65b9933bb571c5 (diff) | |
download | dotfiles-21a8cd5be238acd20b6196674d27d830f879fd0f.tar.bz2 dotfiles-21a8cd5be238acd20b6196674d27d830f879fd0f.tar.xz dotfiles-21a8cd5be238acd20b6196674d27d830f879fd0f.zip |
Backup music with systemd
-rw-r--r-- | .linux/systemd/music-backup.service | 12 | ||||
-rw-r--r-- | .linux/systemd/music-backup.timer | 10 | ||||
-rwxr-xr-x | bin/backup-sync.sh | 92 | ||||
-rwxr-xr-x | bin/walkman-sync.sh | 10 |
4 files changed, 32 insertions, 92 deletions
diff --git a/.linux/systemd/music-backup.service b/.linux/systemd/music-backup.service new file mode 100644 index 0000000..7a83c15 --- /dev/null +++ b/.linux/systemd/music-backup.service | |||
@@ -0,0 +1,12 @@ | |||
1 | [Unit] | ||
2 | Description=backup music with rsync | ||
3 | |||
4 | [Service] | ||
5 | Type=oneshot | ||
6 | |||
7 | ExecCondition=ping -q -c1 -W1 -w1 nas.sea1.crute.me | ||
8 | |||
9 | ExecStart=rsync -rltvp -e "ssh -i /home/mcrute/.ssh/id_rsa.musicbackup -l mcrute" --delete-excluded --delete-during --exclude '/Swinsian/Artwork/' /home/mcrute/Music/Swinsian nas.sea1.crute.me:/mnt/data/Mike/Music/ | ||
10 | |||
11 | [Install] | ||
12 | WantedBy=timers.target | ||
diff --git a/.linux/systemd/music-backup.timer b/.linux/systemd/music-backup.timer new file mode 100644 index 0000000..fdf7e13 --- /dev/null +++ b/.linux/systemd/music-backup.timer | |||
@@ -0,0 +1,10 @@ | |||
1 | [Unit] | ||
2 | Description=Run music backup with rsync daily | ||
3 | |||
4 | [Timer] | ||
5 | OnCalendar=*-*-* 00:00:00 | ||
6 | AccuracySec=8h | ||
7 | RandomizedDelaySec=15m | ||
8 | |||
9 | [Install] | ||
10 | WantedBy=default.target | ||
diff --git a/bin/backup-sync.sh b/bin/backup-sync.sh deleted file mode 100755 index 710a08d..0000000 --- a/bin/backup-sync.sh +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # Sync laptop music to external storage | ||
4 | # | ||
5 | flags="" | ||
6 | |||
7 | while getopts t opt; do | ||
8 | case $opt in | ||
9 | t) # test | ||
10 | shift; flags="-n" | ||
11 | esac | ||
12 | done | ||
13 | |||
14 | music_backup() { | ||
15 | rsync -rltvp $flags --delete-excluded --delete-during \ | ||
16 | --exclude '/Swinsian/Artwork/' \ | ||
17 | ~/Music/Swinsian \ | ||
18 | schroeder.sea1.crute.me:/mnt/data/Mike/Music/ | ||
19 | } | ||
20 | |||
21 | case "$1" in | ||
22 | |||
23 | virt) | ||
24 | restic \ | ||
25 | -r rest:http://172.16.0.167:6275/mcrute-devices \ | ||
26 | -p ~/.restic-key \ | ||
27 | backup \ | ||
28 | --exclude-file ~/.backup-filter-virt \ | ||
29 | $HOME | ||
30 | |||
31 | #rsync -rltvp $flags --delete-excluded --delete-during \ | ||
32 | # --filter="merge $HOME/.backup-filter-virt" \ | ||
33 | # "$HOME/" \ | ||
34 | # diskstation.sea1.crute.me:/volume2/Mike/Virt | ||
35 | ;; | ||
36 | |||
37 | laptop) | ||
38 | restic \ | ||
39 | -r rest:http://172.16.0.167:6275/mcrute-devices \ | ||
40 | -p ~/.restic-key \ | ||
41 | backup \ | ||
42 | --exclude-file ~/.backup-filter \ | ||
43 | $HOME | ||
44 | |||
45 | #rsync -rltvp $flags --delete-excluded --delete-during \ | ||
46 | # --filter="merge $HOME/.backup-filter" \ | ||
47 | # "$HOME/" \ | ||
48 | # diskstation.sea1.crute.me:/volume2/Mike/Laptop | ||
49 | |||
50 | #music_backup | ||
51 | ;; | ||
52 | |||
53 | music) | ||
54 | music_backup | ||
55 | ;; | ||
56 | |||
57 | music-portable) | ||
58 | if ! mount | grep " on /mnt/walkman" >/dev/null 2>&1; then | ||
59 | echo "Not mounted" | ||
60 | exit 1 | ||
61 | fi | ||
62 | |||
63 | rsync -rlv $flags --delete-excluded --delete-during \ | ||
64 | --exclude '/Artwork/' \ | ||
65 | ~/Music/Swinsian/ /mnt/walkman/MUSIC/ | ||
66 | ;; | ||
67 | |||
68 | *) | ||
69 | cmds=$(awk -f <(cat - <<-EOF | ||
70 | BEGIN { | ||
71 | split("", a); | ||
72 | } | ||
73 | /[^\)* ]+\)\$/ { | ||
74 | gsub("\\\)", "", \$1); | ||
75 | a[length(a)+1] = \$1; | ||
76 | } | ||
77 | END { | ||
78 | for (i=1; i <= length(a); i++) { | ||
79 | if (i != length(a)) { | ||
80 | printf("%s, ", a[i]); | ||
81 | } else { | ||
82 | printf("%s", a[i]); | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | EOF | ||
87 | ) $0 ) | ||
88 | echo "Sync what? ($cmds)" | ||
89 | exit 1 | ||
90 | ;; | ||
91 | |||
92 | esac | ||
diff --git a/bin/walkman-sync.sh b/bin/walkman-sync.sh new file mode 100755 index 0000000..695be3f --- /dev/null +++ b/bin/walkman-sync.sh | |||
@@ -0,0 +1,10 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | if ! mount | grep " on /mnt/walkman" >/dev/null 2>&1; then | ||
4 | echo "Not mounted" | ||
5 | exit 1 | ||
6 | fi | ||
7 | |||
8 | rsync -rlv $flags --delete-excluded --delete-during \ | ||
9 | --exclude '/Artwork/' \ | ||
10 | ~/Music/Swinsian/ /mnt/walkman/MUSIC/ | ||