-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic script to make a database backup
Also a playbook to download the backup files. It's crude, but in this case something is better than nothing.
- Loading branch information
1 parent
9d215af
commit ad01216
Showing
6 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ rails/config/master.key | |
certs | ||
etc/build-info.txt | ||
etc/certbot-dns-user-credentials.yml | ||
backups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
- hosts: all | ||
become: yes | ||
become_user: root | ||
|
||
vars: | ||
local_backup_dir: ../backups | ||
|
||
tasks: | ||
- name: Make a fresh backup of the database | ||
command: "{{ bin_dir }}/db-backup" | ||
|
||
- name: Download all the files | ||
# Beware it will overwrite existing files | ||
# TODO: Timestamps maybe? | ||
fetch: | ||
src: "{{ item }}" | ||
dest: "{{ local_backup_dir }}/" | ||
flat: yes | ||
fail_on_missing: no | ||
with_items: | ||
- "{{ db_dump_file }}" | ||
- "{{ db_dump_file }}.1" | ||
- "{{ db_dump_file }}.2" | ||
- "{{ db_dump_file }}.3" | ||
- "{{ db_dump_file }}.4" | ||
- "{{ db_dump_file }}.5" | ||
- "{{ db_dump_file }}.6" | ||
- "{{ db_dump_file }}.7" | ||
- "{{ db_dump_file }}.8" | ||
- "{{ db_dump_file }}.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
mkdir -p {{ backups_dir }} | ||
|
||
# Keep a few old backups | ||
for i in {8..0}; do | ||
[[ -f {{ db_dump_file }}.$i ]] && mv {{ db_dump_file }}.$i {{ db_dump_file }}.$((i+1)) | ||
done | ||
mv {{ db_dump_file }} {{ db_dump_file }}.0 | ||
|
||
# Make a new backup | ||
sudo docker-compose exec db bash -c \ | ||
'pg_dump --dbname={{ db_name }} --username={{ db_user }}' | gzip > {{ db_dump_file }} |