mirror of
https://gitlab.crans.org/bde/nk20-scripts
synced 2024-12-25 17:02:23 +00:00
➕ Backup database script
This commit is contained in:
parent
a66ce1ad85
commit
b311d7d51b
11
shell/backup_db
Executable file
11
shell/backup_db
Executable file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
# Create backups directory
|
||||
[[ -d /var/www/note_kfet/backups ]] || (mkdir /var/www/note_kfet/backups && chown www-data:www-data /var/www/note_kfet/backups)
|
||||
date=$(date +%Y-%m-%d)
|
||||
# Backup database and save it as tar archive
|
||||
su postgres -c "pg_dump -F t note_db" | tee "/var/www/note_kfet/backups/$date.tar" > /dev/null
|
||||
# Compress backup as gzip
|
||||
gzip "/var/www/note_kfet/backups/$date.tar"
|
||||
chown www-data:www-data "/var/www/note_kfet/backups/$date.tar.gz"
|
||||
# Delete backups that have more than 30 days
|
||||
find /var/www/note_kfet/backups -type f -mtime +30 -exec rm {} \;
|
Loading…
Reference in New Issue
Block a user