Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • antiz/infrastructure
  • okabe/infrastructure
  • eworm/infrastructure
  • polyzen/infrastructure
  • pitastrudl/infrastructure
  • sjon/infrastructure
  • torxed/infrastructure
  • jinmiaoluo/infrastructure
  • moson/infrastructure
  • serebit/infrastructure
  • ivabus/infrastructure
  • lb-wilson/infrastructure
  • gromit/infrastructure
  • matt-1-2-3/infrastructure
  • jocke-l/infrastructure
  • alucryd/infrastructure
  • maximbaz/infrastructure
  • ainola/infrastructure
  • segaja/infrastructure
  • nl6720/infrastructure
  • peanutduck/infrastructure
  • aminvakil/infrastructure
  • xenrox/infrastructure
  • felixonmars/infrastructure
  • denisse/infrastructure
  • artafinde/infrastructure
  • jleclanche/infrastructure
  • kpcyrd/infrastructure
  • metalmatze/infrastructure
  • kevr/infrastructure
  • dvzrv/infrastructure
  • dhoppe/infrastructure
  • ekkelett/infrastructure
  • seblu/infrastructure
  • lahwaacz/infrastructure
  • klausenbusk/infrastructure
  • alerque/infrastructure
  • hashworks/infrastructure
  • foxboron/infrastructure
  • shibumi/infrastructure
  • lambdaclan/infrastructure
  • ffy00/infrastructure
  • freswa/infrastructure
  • archlinux/infrastructure
44 results
Show changes
Commits on Source (2)
......@@ -76,12 +76,13 @@ or just a sub-directory:
### Mariadb
For Mariadb backups are made using mariabackup to `mysql_backup_dir`.Backups can are made and
restored using the `mariabackup` tool. See also [official MariaDB docs](https://mariadb.com/kb/en/full-backup-and-restore-with-mariabackup/).
For Mariadb backups are made using mariabackup to `backup_mysql_dir`. Backups
are made and can be restored using the `mariadb-backup` tool. See also
[official MariaDB docs](https://mariadb.com/kb/en/full-backup-and-restore-with-mariabackup/).
### PostgreSQL
For PostgreSQL backups are made using pg_dump to `postgres_backup_dir`.
For PostgreSQL backups are made using pg_dump to `backup_postgres_dir`.
Restoring backups can be done with `pg_restore`. See also [official PostgreSQL docs](https://www.postgresql.org/docs/current/app-pgrestore.html).
......
......@@ -7,3 +7,7 @@ backup_hosts:
dir: "~/backup/{{ inventory_hostname }}"
suffix: "-offsite"
borg_cmd: "/usr/bin/borg --remote-path=borg1"
backup_postgres_dir: /root/backup-postgres
backup_mysql_dir: /root/backup-mysql
backup_mysql_defaults: /root/.backup-my.cnf
......@@ -27,31 +27,26 @@
template: src=borg-backup.sh.j2 dest=/usr/local/bin/borg-backup{{ item['suffix'] }}.sh owner=root group=root mode=0755
loop: "{{ backup_hosts }}"
- name: Install postgres backup script
template: src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=0755
when: postgres_backup_dir is defined
- name: Check whether postgres user exists
command: getent passwd postgres
register: check_postgres_user
ignore_errors: true
changed_when: check_postgres_user.stdout | length > 0
- name: Make postgres backup directory
file: path={{ postgres_backup_dir }} owner=root group=root mode=0755 state=directory
when: check_postgres_user is succeeded and postgres_backup_dir is defined
- name: Install mysql backup script
template: src=backup-mysql.sh.j2 dest=/usr/local/bin/backup-mysql.sh owner=root group=root mode=0755
when: mysql_backup_dir is defined
- name: Install mysql backup config
template: src=backup-my.cnf.j2 dest={{ mysql_backup_defaults }} owner=root group=root mode=0644
when: mysql_backup_defaults is defined
- name: Create mysql backup directory
file: path={{ mysql_backup_dir }} state=directory owner=root group=root mode=0755
when: mysql_backup_dir is defined
- name: Set up backup helpers for PostgreSQL databases
when: "'postgresql_servers' in group_names"
block:
- name: Install postgres backup script
template: src=backup-postgres.sh.j2 dest=/usr/local/bin/backup-postgres.sh owner=root group=root mode=0755
- name: Make postgres backup directory
file: path={{ backup_postgres_dir }} owner=root group=root mode=0755 state=directory
- name: Set up backup helpers for MariaDB databases
when: "'mysql_servers' in group_names"
block:
- name: Install mysql backup script
template: src=backup-mysql.sh.j2 dest=/usr/local/bin/backup-mysql.sh owner=root group=root mode=0755
- name: Install mysql backup config
template: src=backup-my.cnf.j2 dest={{ backup_mysql_defaults }} owner=root group=root mode=0644
- name: Create mysql backup directory
file: path={{ backup_mysql_dir }} state=directory owner=root group=root mode=0755
- name: Install systemd services for backup
template: src={{ item }}.j2 dest=/etc/systemd/system/{{ item }} owner=root group=root mode=0644
......
#!/bin/bash
mysql_opts="--defaults-file={{mysql_backup_defaults}}"
backupdir="{{mysql_backup_dir}}"
set -e
mysql_opts="--defaults-file={{ backup_mysql_defaults }}"
backupdir="{{ backup_mysql_dir }}"
[[ ! -d "$backupdir" ]] && mkdir -p "$backupdir"
rm -rf "${backupdir:?}"/*
......
......@@ -3,16 +3,17 @@
# Script to backup all postgres databases individually
#
# Requires local login with `postgres` user and either trusted or peer auth.
#
set -e
DBLIST=($(sudo -u postgres psql -d postgres -qt -c 'SELECT datname from pg_database'))
for db in "${DBLIST[@]}"; do
if [[ $db =~ template[01] ]]; then
continue;
fi
echo "Dumping $db to {{ postgres_backup_dir }}";
sudo -u postgres pg_dump --serializable-deferrable -Fc "$db" > "{{ postgres_backup_dir }}/$db.dump"
echo "Dumping $db to {{ backup_postgres_dir }}";
sudo -u postgres pg_dump --serializable-deferrable -Fc "$db" > "{{ backup_postgres_dir }}/$db.dump"
done
echo "Dumping globals to {{ postgres_backup_dir }}"
sudo -u postgres pg_dumpall --globals-only > "{{ postgres_backup_dir }}/globals.sql.dump"
echo "Dumping globals to {{ backup_postgres_dir }}"
sudo -u postgres pg_dumpall --globals-only > "{{ backup_postgres_dir }}/globals.sql.dump"
......@@ -40,9 +40,11 @@ cleanup() {
trap cleanup EXIT
# Dump databases to /root/backup-{postgres,mysql} before taking a btrfs snapshot
systemctl is-active postgresql && /usr/local/bin/backup-postgres.sh || true
if systemctl is-active mysqld || systemctl is-active mariadb; then
/usr/local/bin/backup-mysql.sh || true
if systemctl is-active postgresql; then
/usr/local/bin/backup-postgres.sh
fi
if systemctl is-active mariadb; then
/usr/local/bin/backup-mysql.sh
fi
if is_btrfs "$src"; then
......
......@@ -23,6 +23,3 @@ mariadb_innodb_flush_log_at_trx_commit: '1'
mariadb_innodb_stats_sample_pages: '32'
mariadb_innodb_thread_concurrency: '8'
mariadb_innodb_file_per_table: true
mysql_backup_dir: '/root/backup-mysql'
mysql_backup_defaults: '/root/.backup-my.cnf'
......@@ -18,5 +18,3 @@ postgres_hosts4: []
postgres_hosts6: []
postgres_ssl_hosts4: []
postgres_ssl_hosts6: []
postgres_backup_dir: '/root/backup-postgres'