Script for pull some folders/files from another server and zip it as backup. Also send a telegram message about succeed/fail backup.
-
Clone repo
git clone https://github.com/annndruha/scp_remote_backup.git && cd scp_remote_backup
-
Create venv
python3 -m venv venv && venv/bin/python3 -m pip install -r requirements.txt
-
Copy example configs from config_examples to repository root:
cp -t . config_examples/.env config_examples/backup_folders.json
-
Change
.env
-file with you tokens and specify remote folders needs to backup inbackup_folders.json
.
-
Make sure that private key is correct permissions like
-r--------
. Change permissions if needed:chmod 400 ~/.ssh/private_key
-
For new servers check that ssh/scp connections is added to known_host, or just connect first time manually:
ssh -p 22 -i ~/.ssh/private_key -r [email protected]
-
Run script manually:
venv/bin/python3 main.py
-
Check backup archive and make shure that all is ok.
- Script scheduling via cron. Edit cronfile:
crontab -e
- Paste this line to end of cronfile, where
/workdir
is path to cloned repo. Next example is every day at 00:00 backup More examples. :0 0 * * * cd /workdir && venv/bin/python3 main.py >> /workdir/logs.txt 2>&1