mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-07 12:00:43 +00:00
commit
527dd9fc68
1 changed files with 23 additions and 0 deletions
23
scripts/backup/backup.sh
Normal file
23
scripts/backup/backup.sh
Normal 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
|
||||||
Loading…
Reference in a new issue