Last active 1716253974

aly's Avatar aly revised this gist 1716253974. Go to revision

1 file changed, 1 insertion, 1 deletion

android-backup.sh

@@ -106,8 +106,8 @@ backup() {
106 106 --compression='lz4' \
107 107 --exclude-caches \
108 108 --exclude='fm:/storage/emulated/0/*/.thumbnails' \
109 + --exclude='pp:/data/data/com.termux/files/home/.config/borg' \
109 110 --exclude='pp:/storage/emulated/0/Android/data' \
110 - # Photos are backed up separately
111 111 --exclude='pp:/storage/emulated/0/DCIM/Camera' \
112 112 --exclude='pp:/storage/emulated/0/Android/obb' \
113 113 "${flags[@]}" \

aly's Avatar aly revised this gist 1715934899. Go to revision

2 files changed, 2 insertions

android-backup.sh

@@ -1,4 +1,5 @@
1 1 #!/data/data/com.termux/files/usr/bin/bash
2 + # https://neverpanic.de/blog/2022/01/25/backing-up-your-android-phone-with-borgbackup/
2 3
3 4 #export HOST=""
4 5 #export HOSTNAME=""

wsl-backup.sh

@@ -1,4 +1,5 @@
1 1 #!/bin/bash
2 + # https://artemis.sh/2022/06/22/how-i-use-borg.html
2 3 source /backup/env.sh
3 4
4 5 borg create "$@" \

aly's Avatar aly revised this gist 1715934807. Go to revision

1 file changed, 6 insertions

push.sh(file created)

@@ -0,0 +1,6 @@
1 + #!/bin/bash
2 + export PATH=/usr/bin
3 + inp=bak
4 + [ -n "$1" ] && inp="$1"
5 + [ -n "$2" ] && param="$2"
6 + sudo find /mnt/EXT4DATA/$inp -type f -mmin -10080 -printf '%P\n' | sudo rclone --config /home/aly/.config/rclone/rclone.conf copy /mnt/EXT4DATA/$inp/ storjs3:ads-$inp/ --fast-list=true --bwlimit=4M --transfers=4 --files-from=- --log-file=/tmp/uploadbak.log $param

aly's Avatar aly revised this gist 1715934611. Go to revision

1 file changed, 172 insertions

android-backup.sh(file created)

@@ -0,0 +1,172 @@
1 + #!/data/data/com.termux/files/usr/bin/bash
2 +
3 + #export HOST=""
4 + #export HOSTNAME=""
5 + #export TARGET="borg@${HOST}:/backup/${HOSTNAME}"
6 + #export BORG_PASSPHRASE=''
7 + #export BORG_RSH=""
8 + source $HOME/backup/env.sh
9 +
10 + declare -a TERMUX_NOTIFICATIONS=()
11 + TERMUX_NOTIFICATION_ID="borgbackup-${HOSTNAME}"
12 +
13 + set -o pipefail
14 +
15 + cleanup() {
16 + for notification in "${TERMUX_NOTIFICATIONS[@]}"; do
17 + termux-notification-remove "$notification"
18 + done
19 + termux-wake-unlock
20 + }
21 +
22 + ##
23 + # Send a notification to the user.
24 + #
25 + # Usage: echo "message" | notify persist identifier [options...]
26 + #
27 + # If persist is 0, the notification will be removed when the script exits.
28 + # Otherwise, it will be kept (e.g. for warning or error messages).
29 + #
30 + # The identifier can be used to overwrite a previous notification with the same
31 + # identifier. This can be useful for progress messages.
32 + #
33 + # Further options are those supported by termux-notification. The message must
34 + # be passed on stdin.
35 + notify() {
36 + local persist=$1
37 + shift
38 + local id="$1"
39 + shift
40 + local -a args=("--group" "${TERMUX_NOTIFICATION_ID}" "--id" "$id")
41 +
42 + if termux-notification "${args[@]}" "$@"; then
43 + if [ "$persist" -eq 0 ]; then
44 + TERMUX_NOTIFICATIONS+=("$id")
45 + fi
46 + fi
47 + }
48 +
49 + msg() {
50 + echo "***" "$@"
51 + }
52 +
53 + info() {
54 + msg "INFO:" "$@"
55 + termux-toast -s "$*"
56 + }
57 +
58 + warn() {
59 + msg "WARN:" "$@"
60 + echo "Warning:" "$@" | \
61 + notify 1 failure \
62 + --title "borgbackup" \
63 + --alert-once \
64 + --priority low
65 + }
66 +
67 + err() {
68 + msg "ERROR:" "$@"
69 + echo "Error:" "$@" | \
70 + notify 1 failure \
71 + --title "borgbackup" \
72 + --alert-once \
73 + --priority high
74 + exit 1
75 + }
76 +
77 + prepare() {
78 + if ! termux-battery-status | grep "status" | grep -qE '"(CHARGING|FULL)"'; then
79 + warn "Not charging, not performing backup"
80 + return 1
81 + fi
82 + if ! termux-wifi-connectioninfo | grep "supplicant_state" | grep -q "COMPLETED"; then
83 + warn "WiFi not connected, not performing backup"
84 + return 1
85 + fi
86 + if ! ping -w 10 -c 3 "$HOST" >/dev/null; then
87 + warn "Failed to ping target $HOST"
88 + return 1
89 + fi
90 + }
91 +
92 + backup() {
93 + local -a flags=()
94 +
95 + # enable interactive output
96 + if [ -t 0 ] && [ -t 1 ]; then
97 + flags+=('--stats' '--progress' '--list')
98 + fi
99 +
100 + info "Starting backup"
101 + ionice -c 3 \
102 + nice -n20 \
103 + borg create \
104 + --noatime \
105 + --compression='lz4' \
106 + --exclude-caches \
107 + --exclude='fm:/storage/emulated/0/*/.thumbnails' \
108 + --exclude='pp:/storage/emulated/0/Android/data' \
109 + # Photos are backed up separately
110 + --exclude='pp:/storage/emulated/0/DCIM/Camera' \
111 + --exclude='pp:/storage/emulated/0/Android/obb' \
112 + "${flags[@]}" \
113 + "${TARGET}::${HOSTNAME}-{utcnow:%Y-%m-%dT%H:%M:%S}" \
114 + /storage/emulated/0/ \
115 + /data/data/com.termux/files/home
116 + }
117 +
118 + prune() {
119 + local -a flags=()
120 +
121 + # enable interactive output
122 + if [ -t 0 ] && [ -t 1 ]; then
123 + flags+=('--stats' '--list')
124 + fi
125 +
126 + info "Pruning old backups..."
127 + borg prune \
128 + --prefix="${HOSTNAME}-" \
129 + --keep-within=14d \
130 + --keep-daily=31 \
131 + --keep-weekly=$((6 * 4)) \
132 + --keep-monthly=$(( 2 * 12 )) \
133 + "${flags[@]}" \
134 + "${TARGET}"
135 + }
136 +
137 + # Run once per day, unless BORGBACKUP_FORCE=1
138 + MARKER_FILE=~/.borgbackup-"${HOSTNAME}-$(date +%Y-%m-%d)"
139 + if [ "${BORGBACKUP_FORCE:-0}" -eq 0 ]; then
140 + if [ "$(date +%H)" -lt 4 ]; then
141 + echo "Backup not yet due, waiting..."
142 + exit 0
143 + elif [ -f "$MARKER_FILE" ]; then
144 + echo "Backup already ran today"
145 + exit 0
146 + fi
147 + fi
148 +
149 + if ! prepare; then
150 + info "Server connectivity or charging status does not meet expectations, skipping backup."
151 + exit 1
152 + fi
153 + rm -f ~/.borgbackup-"${HOSTNAME}"-*
154 + touch "$MARKER_FILE"
155 +
156 + trap "cleanup" EXIT
157 + termux-wake-lock
158 + notify 0 progress \
159 + --alert-once \
160 + --ongoing \
161 + --priority low \
162 + --title "borgbackup" \
163 + --content "Running backup for ${HOSTNAME}"
164 +
165 + if ! backup; then
166 + err "Backup failed, aborting!"
167 + fi
168 + if ! prune; then
169 + warn "Pruning failed. Continuing anyway."
170 + fi
171 +
172 + info "Backup finished successfully"

aly's Avatar aly revised this gist 1715919829. Go to revision

1 file changed, 50 insertions

wsl-backup.sh(file created)

@@ -0,0 +1,50 @@
1 + #!/bin/bash
2 + source /backup/env.sh
3 +
4 + borg create "$@" \
5 + --stats \
6 + --one-file-system \
7 + --compression auto,zstd,3 \
8 + --exclude /backup \
9 + --exclude /root/.cache \
10 + --exclude /opt/nvidia \
11 + --exclude **/cuda** \
12 + --exclude /var/cache \
13 + --exclude /usr/share \
14 + --exclude **/.pyenv \
15 + --exclude **/.cache \
16 + --exclude **/cache \
17 + --exclude **/Cache \
18 + --exclude **/Code\ Cache \
19 + --exclude **/ccache \
20 + --exclude **/.git \
21 + --exclude **/.env \
22 + --exclude **/.conda \
23 + --exclude **/miniconda3 \
24 + --exclude **/.docker \
25 + --exclude **/.nuget \
26 + --exclude **/User\ Data \
27 + --exclude **/QtWebEngine/Default \
28 + --exclude **/Service\ Worker \
29 + --exclude **/FL\ Studio \
30 + --exclude **/modules \
31 + --exclude **/Lib \
32 + --exclude **/site-packages \
33 + --exclude **/node_modules \
34 + --exclude **/Persistent \
35 + --exclude **/AppData/Roaming/Cakewalk \
36 + --exclude **/AppData/Local/Temp \
37 + --exclude **/Packages \
38 + --exclude **/Package\ Cache \
39 + --exclude /tmp \
40 + --exclude /usr/lib \
41 + --exclude **/MediaCover \
42 + --exclude **venv \
43 + --exclude /home/**/.local/lib \
44 + --exclude **/virtualenv \
45 + --exclude **/virtualenvs \
46 + --exclude **/Temp \
47 + "$REPO::{hostname}-{now:%Y-%m-%d}" \
48 + / \
49 + /mnt/c/Users \
50 + /mnt/c/ProgramData
Newer Older