Преглед на файлове

Adding postgresql backup with Readme

Sebastian Vendt преди 1 година
родител
ревизия
83a9ebd559
променени са 2 файла, в които са добавени 24 реда и са изтрити 0 реда
  1. 10 0
      postgresqlBackup/Readme.md
  2. 14 0
      postgresqlBackup/backup_postgresql

+ 10 - 0
postgresqlBackup/Readme.md

@@ -0,0 +1,10 @@
+# Backing up Postgresql databases running in Docker container
+## Configuration
+Please create a configuration file which defines the following variables. ```
+#Where to put the sql dumps
+backupFilepath="/var/joplin/postgresql_backup/"
+#How many dumps shall be kept
+rotationDays=7
+#Database settings
+dockerContainerName=docker_postgresql dbUser=joplin dbPasswd=123456789 dbName=joplin ``` Pass this configuration file as parameter to the script. To automate the backup job, I recommend to put the script in your crontab: ``` 50 2 
+* * * root /root/scripts/backup/postgresqlBackup/backup_postgresql /root/scripts/backup/postgresqlBackup/joplinBackup.conf ```

+ 14 - 0
postgresqlBackup/backup_postgresql

@@ -0,0 +1,14 @@
+#!/bin/bash
+
+#Source external configuration
+. $1
+
+today=$(date +"%Y-%m-%d_%H-%M")
+filename="${today}_${dbName}_Backup.sql"
+fullBackupFileName="${backupFilepath}${filename}"
+
+#Backup Job
+docker exec -i ${dockerContainername} /bin/bash -c "PGPASSWORD=${dbpasswd} pg_dump --username ${dbUser} ${dbName}" > $fullBackupFileName
+
+#Backup rotation - Delete everything older than rotationDays
+find $backupFilePath -type f -mtime +$rotationDays -name '*.sql' -execdir rm -- '{}' \;