Skip to content
GitLab
Explore
Sign in
Commits on Source (1)
➕
Backup database script
· b311d7d5
ynerant
authored
Aug 06, 2020
b311d7d5
Hide whitespace changes
Inline
Side-by-side
shell/backup_db
0 → 100755
View file @
b311d7d5
#!/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
{}
\;
\ No newline at end of file