mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-19 04:18:52 +00:00
chore: add backup.sh script
This commit is contained in:
parent
b419c7e9dd
commit
c3dc264359
1 changed files with 20 additions and 0 deletions
20
scripts/backup/backup.sh
Normal file
20
scripts/backup/backup.sh
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#!/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
|
||||
Loading…
Reference in a new issue