keep weekly weblate backups on backup01
This commit is contained in:
parent
95bb3249e6
commit
e0941ac2de
5 changed files with 100 additions and 0 deletions
|
@ -7,6 +7,7 @@ datacenter: iad2
|
||||||
ansible_ifcfg_blocklist: true
|
ansible_ifcfg_blocklist: true
|
||||||
|
|
||||||
grokmirror_topdir: /fedora_backups/grokmirror
|
grokmirror_topdir: /fedora_backups/grokmirror
|
||||||
|
weblate_backup_topdir: /fedora_backups/misc/weblate
|
||||||
|
|
||||||
dns1: 10.3.163.33
|
dns1: 10.3.163.33
|
||||||
dns2: 10.3.163.34
|
dns2: 10.3.163.34
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
nfs_mount_opts: "rw,hard,bg,intr,noatime,nodev,nosuid,sec=sys,nfsvers=3",
|
nfs_mount_opts: "rw,hard,bg,intr,noatime,nodev,nosuid,sec=sys,nfsvers=3",
|
||||||
nfs_src_dir: 'fedora_backups' }
|
nfs_src_dir: 'fedora_backups' }
|
||||||
- grokmirror_mirror
|
- grokmirror_mirror
|
||||||
|
- weblate_backup
|
||||||
|
|
||||||
pre_tasks:
|
pre_tasks:
|
||||||
- import_tasks: "{{ tasks_path }}/yumrepos.yml"
|
- import_tasks: "{{ tasks_path }}/yumrepos.yml"
|
||||||
|
|
62
roles/weblate-backup/tasks/main.yml
Normal file
62
roles/weblate-backup/tasks/main.yml
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
- name: Install packages
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- borgbackup
|
||||||
|
state: present
|
||||||
|
tags:
|
||||||
|
- weblate_backup
|
||||||
|
|
||||||
|
- name: Create a non root user to run the code
|
||||||
|
user:
|
||||||
|
name: _backup_weblate
|
||||||
|
tags:
|
||||||
|
- weblate_backup
|
||||||
|
|
||||||
|
- name: Copy private key
|
||||||
|
copy:
|
||||||
|
src: "{{ private }}/files/weblate/id_rsa"
|
||||||
|
dest: ~_backup_weblate/.ssh/id_rsa
|
||||||
|
owner: _backup_weblate
|
||||||
|
group: _backup_weblate
|
||||||
|
mode: 0600
|
||||||
|
tags:
|
||||||
|
- weblate_backup
|
||||||
|
|
||||||
|
- name: Copy passphrase file
|
||||||
|
copy:
|
||||||
|
src: "{{ private }}/files/weblate/borg_passphrase"
|
||||||
|
dest: ~_backup_weblate/.borgpass
|
||||||
|
owner: _backup_weblate
|
||||||
|
group: _backup_weblate
|
||||||
|
mode: 0600
|
||||||
|
tags:
|
||||||
|
- weblate_backup
|
||||||
|
|
||||||
|
- name: Install backup script
|
||||||
|
template:
|
||||||
|
src: weblate-backup
|
||||||
|
dest: /usr/local/bin/weblate-backup
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0755
|
||||||
|
tags:
|
||||||
|
- weblate_backup
|
||||||
|
|
||||||
|
- name: Setup cron job
|
||||||
|
template:
|
||||||
|
src: cron-weblate-backup
|
||||||
|
dest: /etc/cron.d/cron-weblate-backup
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0644
|
||||||
|
tags:
|
||||||
|
- weblate_backup
|
||||||
|
|
||||||
|
- name: Create directory to mirror backups to
|
||||||
|
file:
|
||||||
|
dest: "{{ weblate_backup_topdir }}"
|
||||||
|
mode: 0755
|
||||||
|
state: directory
|
||||||
|
owner: _backup_weblate
|
||||||
|
tags:
|
||||||
|
- weblate_backup
|
1
roles/weblate-backup/templates/cron-weblate-backup
Normal file
1
roles/weblate-backup/templates/cron-weblate-backup
Normal file
|
@ -0,0 +1 @@
|
||||||
|
0 2 * * 0 _weblate_backup /usr/local/bin/weblate-backup
|
35
roles/weblate-backup/templates/weblate-backup
Executable file
35
roles/weblate-backup/templates/weblate-backup
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
pass_file=~/.borgpass
|
||||||
|
backup_prefix=weblate_backup
|
||||||
|
dest_backup={{ weblate_backup_topdir }}
|
||||||
|
|
||||||
|
dest_backup_file=${dest_backup}/${backup_prefix}_$(date +%Y%m%d%H%M%S).tar.gz
|
||||||
|
export BORG_RSH="ssh -o StrictHostKeyChecking=no"
|
||||||
|
export BORG_REPO="ssh://u164666-sub8@u164666-sub8.your-storagebox.de:23/./backups"
|
||||||
|
|
||||||
|
#############################
|
||||||
|
|
||||||
|
if [ ! -f "$pass_file" ]; then
|
||||||
|
echo "Passphrase file not found!"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
export BORG_PASSCOMMAND="cat $pass_file"
|
||||||
|
|
||||||
|
echo "* listing backup ..."
|
||||||
|
last_backup=$(borg list --last 1 | awk '{print $1}')
|
||||||
|
if [ -z "$last_backup" ]; then
|
||||||
|
echo "* no backup found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "* last backup is $last_backup"
|
||||||
|
|
||||||
|
|
||||||
|
echo "* extracting backup to $dest_backup ..."
|
||||||
|
borg export-tar ::$last_backup $dest_backup_file
|
||||||
|
echo "* extraction complete"
|
||||||
|
|
||||||
|
echo "* purging old backups ..."
|
||||||
|
# 56 days = 8 weeks
|
||||||
|
find ${dest_backup} -name ${backup_prefix}\*.gz -ctime +56 -exec rm -v {} \;
|
||||||
|
echo "* purge complete"
|
Loading…
Add table
Add a link
Reference in a new issue