Merge pull request #206 from EETagent/add_util_scripts

Utility scripts
This commit is contained in:
Sebastian Pravda 2023-02-23 11:35:51 +01:00 committed by GitHub
commit 527dd9fc68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

23
scripts/backup/backup.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
# get the current datetime and create a directory with that name
NOW=$(date +"%Y-%m-%d_%H-%M-%S")
mkdir -p /opt/backup/$NOW
# copy all files in directory to the backup directory
cp -r /root/Portfolio/data-backend /opt/backup/$NOW
# run pg_dump to backup the database
pg_dump postgresql://DB_USERNAME:DB_PASSWORD@localhost:5432/DATABASE > /opt/backup/$NOW/db.sql
# compress the backup directory
tar -zcvf /opt/backup/$NOW.tar.gz /opt/backup/$NOW
# remove the uncompressed backup directory
rm -rf /opt/backup/$NOW
# scp the backup to the remote server
scp /opt/backup/$NOW.tar.gz USERNAME@SERVER_IP:/home/zalohy/backups/$NOW.tar.gz
# remove the local backup
rm /opt/backup/$NOW.tar.gz