Skip to content

Instantly share code, notes, and snippets.

@TechnoSparks
Last active January 20, 2022 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TechnoSparks/6eb91c9fc6f13ae85d0d9ffa170aedfa to your computer and use it in GitHub Desktop.
Save TechnoSparks/6eb91c9fc6f13ae85d0d9ffa170aedfa to your computer and use it in GitHub Desktop.
simple script to trigger backup / restore over SSH using rclone

Backup and Restore Script for Termux

simple script to trigger backup / restore over SSH using rclone

Setup

  • A termux environment,
    • SD card All Files access enabled
    • termux-setup-storage configured
  • An backup server/path
  • Modify scripts based on your path of course
  • Script must be executable of course. chmod ugo+x the scripts
#!/bin/env bash
# Boilerplate
echo ==================================================
title="SD Backup"
div="--------------------------------------------------"
echo $title
echo $div
echo
curdir=`pwd`
x=`tput sgr0`
r=`tput setaf 1`
g=`tput setaf 2`
bw=`tput setab 7`
bb=`tput setab 0`
bd=`tput bold`
ul=`tput smul`
xul=`tput rmul`
# Local
rclone_opt="--exclude-from $HOME/rclone-excl/exclude-sd-backup.txt \
--progress --create-empty-src-dirs"
bkpNeedle=/sdcard/backup-needle.txt
src="/sdcard"
dest="technopc:/E:/sdcard"
echo Checking needle
if ! [ -f $bkpNeedle ]; then # if there NO needle, refuse backup
echo ${r}${bd}Backup Refused.${x}
echo Needle not found
echo Backup is lethal to do. There are nothing in sdcard!
exit 1
else
echo ${g}${bd}Needle found - good to go!${x}
echo $div
fi
rclone sync "$src" "$dest" $rclone_opt
echo $div
echo Needle regen
echo date +%s > $bkpNeedle
echo Backup done
read -p "Any key to continue" -n 1 -r
#!/bin/env bash
# Boilerplate
echo ==================================================
title="Apps Restore"
div="--------------------------------------------------"
echo $title
echo $div
echo
curdir=`pwd`
x=`tput sgr0`
r=`tput setaf 1`
g=`tput setaf 2`
bw=`tput setab 7`
bb=`tput setab 0`
bd=`tput bold`
ul=`tput smul`
xul=`tput rmul`
# Local
rclone_opt="--exclude-from $HOME/rclone-excl/exclude-sd-backup.txt \
--progress --create-empty-src-dirs"
bkpNeedle=/sdcard/backup-needle.txt
src="technopc:/E:/sdcard"
dest="/sdcard"
echo Checking needle
if [ -f $bkpNeedle ]; then # if there is needle, refute restore
echo ${r}${bd}Restore Refused.${x}
echo May result in newer files being replaced, and deleted files restored!
read -p "Continue anyway? Y/n" -r
if ! [[ $REPLY =~ ^[Yy]$ ]]; then
echo Operation aborted
read -p "Any key to continue" -n 1 -r
exit 1
else
echo ${r}${bd}Restoring anyway.${x}
fi
else
echo ${g}${bd}Needle not found - good to go!${x}
echo $div
fi
rclone copy "$src" "$dest" $rclone_opt
echo $div
echo Needle regen
echo date +%s > $bkpNeedle
echo Backup done
read -p "Any key to continue" -n 1 -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment