From 5bd6e59ed2509a7191b6d02a3bef52541a6e4021 Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Sat, 23 Jul 2022 00:44:24 +0300 Subject: [PATCH] blogs: Add daily backup --- cookbooks/blogs/recipes/default.rb | 8 ++++++++ .../blogs/templates/default/backup.cron.erb | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 cookbooks/blogs/templates/default/backup.cron.erb diff --git a/cookbooks/blogs/recipes/default.rb b/cookbooks/blogs/recipes/default.rb index a3c8eebee..e876c0a5c 100644 --- a/cookbooks/blogs/recipes/default.rb +++ b/cookbooks/blogs/recipes/default.rb @@ -27,6 +27,7 @@ package %W[ gcc g++ libsqlite3-dev + sqlite3 ] directory "/srv/blogs.openstreetmap.org" do @@ -83,3 +84,10 @@ cron_d "blogs" do command "/usr/local/bin/blogs-update" mailto "admins@openstreetmap.org" end + +template "/etc/cron.daily/blogs-backup" do + source "blogs-backup.erb" + owner "root" + group "root" + mode "0755" +end diff --git a/cookbooks/blogs/templates/default/backup.cron.erb b/cookbooks/blogs/templates/default/backup.cron.erb new file mode 100644 index 000000000..382989ab2 --- /dev/null +++ b/cookbooks/blogs/templates/default/backup.cron.erb @@ -0,0 +1,17 @@ +#!/bin/sh + +# DO NOT EDIT - This file is being maintained by Chef + +T=$(mktemp -d -t -p /var/tmp blogs.XXXXXXXXXX) +D=$(date +%Y-%m-%d) +B=blogs-$D.tar.gz + +mkdir $T/blogs-$D +sqlite3 /srv/blogs.openstreetmap.org/planet.db ".backup $T/blogs-$D/planet.db" + +export RSYNC_RSH="ssh -ax" + +nice tar --create --dereference --directory=$T blogs-$D | nice gzip --rsyncable -9 > $T/$B +nice rsync --preallocate --fuzzy $T/$B backup::backup + +rm -rf $T -- 2.39.5