Compare commits
No commits in common. "master" and "develop" have entirely different histories.
17
README.md
17
README.md
@ -17,25 +17,18 @@ and it will notify you when complete.
|
|||||||
Alternatively, you can add a Termux widget to your home screen (`./setup.sh` auto-installs in the `.shortcuts` directory), so backups can be made with a single tap from the home screen.
|
Alternatively, you can add a Termux widget to your home screen (`./setup.sh` auto-installs in the `.shortcuts` directory), so backups can be made with a single tap from the home screen.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
1 line installation:
|
Quick, 4 line installation:
|
||||||
```bash
|
```bash
|
||||||
curl -Ls https://linx.austenwares.com/selif/0182lycx.sh | bash
|
apt update
|
||||||
```
|
apt install -y git rsync openssh
|
||||||
|
|
||||||
Manual 4 line installation:
|
|
||||||
```bash
|
|
||||||
# Install rsync/git/ssh only if they aren't already present
|
|
||||||
{ command -v rsync && command -v git && command -v ssh; } >/dev/null || { apt update && apt install -y git rsync openssh; }
|
|
||||||
git clone https://gitea.austenwares.com/stonewareslord/borg-remote-android
|
git clone https://gitea.austenwares.com/stonewareslord/borg-remote-android
|
||||||
env bash borg-remote-android/setup.sh
|
env bash borg-remote-android/setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Manual one-liner:
|
Same installation as a one-liner
|
||||||
```bash
|
```bash
|
||||||
{ command -v rsync && command -v git && command -v ssh; } >/dev/null || { apt update && apt install -y git rsync openssh; } && git clone https://gitea.austenwares.com/stonewareslord/borg-remote-android && env bash borg-remote-android/setup.sh
|
apt update && apt install -y git rsync openssh && git clone https://gitea.austenwares.com/stonewareslord/borg-remote-android && env bash borg-remote-android/setup.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
[QR code installation (paste into Termux)](https://linx.austenwares.com/selif/w1x8uezq.png)
|
|
||||||
|
|
||||||
## Updating
|
## Updating
|
||||||
The entire config is stored in `env`, which is in `.gitignore`, so running a simple `git pull` will update without losing custom changes.
|
The entire config is stored in `env`, which is in `.gitignore`, so running a simple `git pull` will update without losing custom changes.
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#!/data/data/com.termux/files/usr/bin/bash
|
#!/data/data/com.termux/files/usr/bin/bash
|
||||||
# Initialize
|
# Initialize
|
||||||
# if [ -z "$STY" ]; then exec screen -m -S backup-android /bin/bash "$0"; fi
|
|
||||||
ABSPATH="$(readlink -f "$BASH_SOURCE")"
|
ABSPATH="$(readlink -f "$BASH_SOURCE")"
|
||||||
set -x
|
|
||||||
cd "${ABSPATH%/*}" || { echo "Cannot change directory" >&2; exit 1; }
|
cd "${ABSPATH%/*}" || { echo "Cannot change directory" >&2; exit 1; }
|
||||||
test -f ./env && source ./env || { echo "Unable to source user variables in $PWD"; exit 1; }
|
test -f ./env && source ./env || { echo "Unable to source user variables in $PWD"; exit 1; }
|
||||||
|
|
||||||
@ -27,33 +25,14 @@ function time_diff {
|
|||||||
printf '%ds\n' $S
|
printf '%ds\n' $S
|
||||||
}
|
}
|
||||||
|
|
||||||
function prune() {
|
|
||||||
if [ -z "$PRUNE_COMMAND" ]; then
|
|
||||||
echo "Not pruning" >&2
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
run_remote "${PRUNE_COMMAND[@]}" "$BORG_REPO"
|
|
||||||
}
|
|
||||||
function backup() {
|
function backup() {
|
||||||
# First, we need to rsync our changes to the host
|
# First, we need to rsync our changes to the host
|
||||||
echo "Running rsync..."
|
echo "Running rsync..."
|
||||||
local RETRIES=10
|
$RSYNC_COMMAND "$SOURCE_LOCATION" "$REMOTE_HOST:$DESTINATION_LOCATION" || return 1
|
||||||
while (( RETRIES > 0 )); do
|
|
||||||
# Try to rsync
|
|
||||||
"${RSYNC_COMMAND[@]}" "$SOURCE_LOCATION" "$REMOTE_HOST:$DESTINATION_LOCATION" && break
|
|
||||||
(( RETRIES-- ))
|
|
||||||
echo "rsync failed. Retrying $RETRIES more times. Sleeping 10s"
|
|
||||||
sleep 10s
|
|
||||||
done
|
|
||||||
|
|
||||||
if (( RETRIES == 0 )); then
|
|
||||||
# We exceeded the retry limit. Fail
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Next, instruct the host to create a borg
|
# Next, instruct the host to create a borg
|
||||||
echo "Running borg..."
|
echo "Running borg..."
|
||||||
run_remote "${CREATE_COMMAND[@]}" "$BORG_REPO::$HOSTNAME-$(uuidgen)" . || return 2
|
./run_remote.sh nohup sh -c "cd \"$DESTINATION_LOCATION\"; $BORG_COMMAND \"$BORG_REPO::$HOSTNAME-$(uuidgen)\" \"$DESTINATION_LOCATION\"" || return 2
|
||||||
}
|
}
|
||||||
|
|
||||||
# Take wakelock so we don't fall asleep
|
# Take wakelock so we don't fall asleep
|
||||||
@ -65,9 +44,6 @@ backup
|
|||||||
RESULT=$?
|
RESULT=$?
|
||||||
DURATION="$(time_diff "$(date +%s)" "$START_TIME" )"
|
DURATION="$(time_diff "$(date +%s)" "$START_TIME" )"
|
||||||
|
|
||||||
# Prune
|
|
||||||
prune
|
|
||||||
|
|
||||||
echo "Completed $(date +%F-%T)"
|
echo "Completed $(date +%F-%T)"
|
||||||
echo "Duration: $DURATION"
|
echo "Duration: $DURATION"
|
||||||
|
|
||||||
@ -79,5 +55,3 @@ fi
|
|||||||
|
|
||||||
# Remove our wakelock
|
# Remove our wakelock
|
||||||
termux-wake-unlock
|
termux-wake-unlock
|
||||||
printf "^c to exit"
|
|
||||||
cat
|
|
||||||
|
51
env.dist
51
env.dist
@ -1,51 +0,0 @@
|
|||||||
EXCLUDES=(
|
|
||||||
"/syncthing"
|
|
||||||
"/Movies"
|
|
||||||
".thumbnails"
|
|
||||||
"/Android"
|
|
||||||
"/Download/Images"
|
|
||||||
)
|
|
||||||
RSYNC_COMMAND=(
|
|
||||||
rsync
|
|
||||||
--partial
|
|
||||||
--info=progress2
|
|
||||||
--verbose
|
|
||||||
--no-i-r
|
|
||||||
-a
|
|
||||||
--delete
|
|
||||||
"${EXCLUDES[@]/#/--exclude=}"
|
|
||||||
)
|
|
||||||
SOURCE_LOCATION="/storage/emulated/0/"
|
|
||||||
HOSTNAME="android-phone"
|
|
||||||
REMOTE_HOST="user@example.com"
|
|
||||||
DESTINATION_LOCATION="~/tmp/borg/$HOSTNAME/"
|
|
||||||
BORG_REPO="runner2:borg/$HOSTNAME"
|
|
||||||
BORG_COMMAND=(
|
|
||||||
borg
|
|
||||||
--remote-path borg1
|
|
||||||
--verbose
|
|
||||||
--progress
|
|
||||||
)
|
|
||||||
CREATE_COMMAND=(
|
|
||||||
"${BORG_COMMAND[@]}"
|
|
||||||
create
|
|
||||||
--stats
|
|
||||||
--one-file-system
|
|
||||||
--exclude-caches
|
|
||||||
--compression=auto,lzma
|
|
||||||
)
|
|
||||||
PRUNE_COMMAND=(
|
|
||||||
"${BORG_COMMAND[@]}"
|
|
||||||
prune
|
|
||||||
--list
|
|
||||||
--keep-daily=7
|
|
||||||
--keep-weekly=4
|
|
||||||
--keep-monthly=2
|
|
||||||
)
|
|
||||||
run_remote() {
|
|
||||||
if (( $# == 0 )); then
|
|
||||||
echo "No arguments given to run_remote" >&2
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
ssh "$REMOTE_HOST" -- "cd" "$DESTINATION_LOCATION" "&&" "pwd" "&&" "${@}"
|
|
||||||
}
|
|
5
run_remote.sh
Executable file
5
run_remote.sh
Executable file
@ -0,0 +1,5 @@
|
|||||||
|
#!/data/data/com.termux/files/usr/bin/bash
|
||||||
|
ABSPATH="$(readlink -f "$BASH_SOURCE")"
|
||||||
|
cd "${ABSPATH%/*}" || { echo "Cannot change directory" >&2; exit 1; }
|
||||||
|
test -f ./env && source ./env || { echo "Unable to source user variables"; exit 1; }
|
||||||
|
ssh "$REMOTE_HOST" -- "$@"
|
Loading…
x
Reference in New Issue
Block a user