Created
October 8, 2020 07:03
-
-
Save Knapoc/248586aefcfd765353ee2e28a99c41e6 to your computer and use it in GitHub Desktop.
roborock-backup.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TEMP_DIR="/tmp/$(date '+%Y%m%d')_roborock_backup" | |
BACKUP_LOCATION="~/Stuff/Roborock" | |
BACKUP_NAME="$(date +"%Y%m%d")_roborock_backup.tar.xz" | |
BACKUP_FILE="${BACKUP_LOCATION}/${BACKUP_NAME}" | |
VACUUM_USER="root" | |
VACUUM_HOST="roborock" | |
REMOTE_DATA_DIR="/mnt/data" | |
IDENTITY_FILE="~/.ssh/id_rsa" | |
FILES_TO_BACKUP="{rockrobo/lab.cfg,rockrobo/user_map0,rockrobo/last_map,rockrobo/robot.db,rockrobo/PersistData_1.data,rockrobo/PersistData_2.data,rockrobo/StartPos.data,valetudo/config.json}" | |
SCP_COMMAND="scp -i ${IDENTITY_FILE} ${VACUUM_USER}@${VACUUM_HOST}:${REMOTE_DATA_DIR}/${FILES_TO_BACKUP} ${TEMP_DIR}" | |
make_temp_dir () { | |
mkdir ${TEMP_DIR} | |
} | |
copy_files () { | |
if [ -d ${TEMP_DIR} ] | |
then | |
echo "Copying files to backup from remote location via scp." | |
${SCP_COMMAND} | |
else | |
echo "Error: Directory ${TEMP_DIR} does not exists." | |
fi | |
} | |
compress_backup_dir () { | |
tar -cJf ${BACKUP_FILE} -C ${TEMP_DIR} . | |
} | |
remove_temp_dir () { | |
rm -rf ${TEMP_DIR} | |
} | |
make_temp_dir && copy_files && compress_backup_dir && remove_temp_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment