Skip to content
Snippets Groups Projects
Commit 65093f9d authored by Michiel de Jong's avatar Michiel de Jong
Browse files

merge backups-fixes branch

parent 78f540b4
No related branches found
No related tags found
No related merge requests found
...@@ -49,9 +49,7 @@ Make sure you read [getting started](getting-started-as-a-hoster.md) first. ...@@ -49,9 +49,7 @@ Make sure you read [getting started](getting-started-as-a-hoster.md) first.
approved cert into place, start a container running the image requested, update haproxy config, and restart the haproxy container. approved cert into place, start a container running the image requested, update haproxy config, and restart the haproxy container.
* set up a git repo for the new site on the backup server (see http://www.git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server again), and for instance if you called the backup repo example.com.git and your backup server is in /etc/hosts on k3 as 'bu25', ssh into k3 and run: * set up a git repo for the new site on the backup server (see http://www.git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server again), and for instance if you called the backup repo example.com.git and your backup server is in /etc/hosts on k3 as 'bu25', ssh into k3 and run:
echo "git@bu25:/opt/git/example.com.git" > /data/per-user/example.com/backup/BACKUPDEST sh scripts/backup-init.sh example.com git@bu25:/opt/git/example.com.git
USER=example.com
/data/indiehosters/importers/backup-init.sh
* Test the site using your /etc/hosts. You should see the data from the git repo on both http and https. * Test the site using your /etc/hosts. You should see the data from the git repo on both http and https.
* Switch DNS and monitoring. * Switch DNS and monitoring.
#!/bin/bash -eux
echo initializing backups for $USER
mkdir -p /data/per-user/$USER/backup/mysql
mkdir -p /data/per-user/$USER/backup/www
git config --global user.email "backups@`hostname`"
git config --global user.name "`hostname` hourly backups"
git config --global push.default simple
cd /data/per-user/$USER/backup/
git init
echo "backups of $USER at IndieHosters server `hostname`" > README.md
git add README.md
git commit -m"initial commit"
if [ -e /data/per-user/$USER/backup/BACKUPDEST ]; then
cd /data/per-user/$USER/backup/
git remote add destination `cat /data/per-user/$USER/backup/BACKUPDEST`
git push -u destination master
fi
...@@ -11,18 +11,32 @@ if [ -e /data/per-user/$USER/mysql ]; then ...@@ -11,18 +11,32 @@ if [ -e /data/per-user/$USER/mysql ]; then
-h db > /data/per-user/$USER/backup/mysql/dump.sql -h db > /data/per-user/$USER/backup/mysql/dump.sql
fi fi
if [ -e /data/per-user/$USER/wordpress-subdir ]; then if [ -e /data/per-user/$USER/wordpress ]; then
echo backing up www from wordpress-subdir for $USER echo backing up www from wordpress for $USER
mkdir -p /data/per-user/$USER/backup/www/wordpress-subdir/ mkdir -p /data/per-user/$USER/backup/www/wordpress/
cp /data/per-user/$USER/wordpress-subdir/.env /data/per-user/$USER/backup/www/wordpress-subdir/.env cp /data/per-user/$USER/wordpress/.env /data/per-user/$USER/backup/www/wordpress/.env
rsync -r /data/per-user/$USER/wordpress-subdir/data/wp-content /data/per-user/$USER/backup/www/wordpress-subdir/wp-content rsync -r /data/per-user/$USER/wordpress/data/wp-content /data/per-user/$USER/backup/www/wordpress/wp-content
if [ -e /data/per-user/$USER/wordpress-subdir/data/GITURL ]; then fi
cp /data/per-user/$USER/wordpress-subdir/data/GITURL /data/per-user/$USER/backup/www/wordpress-subdir/GITURL
if [ -e /data/per-user/$USER/nginx ]; then
echo backing up www from nginx for $USER
mkdir -p /data/per-user/$USER/backup/www/nginx/
if [ -e /data/per-user/$USER/nginx/data/GITURL ]; then
cp /data/per-user/$USER/nginx/data/GITURL /data/per-user/$USER/backup/www/nginx/GITURL
else
rsync -r /data/per-user/$USER/nginx/data/www-content /data/per-user/$USER/backup/www/nginx/www-content
fi fi
fi fi
echo copying TLS cert
mkdir -p /data/per-user/$USER/backup/TLS/
cp /data/server-wide/haproxy/approved-certs/$USER.pem /data/per-user/$USER/backup/TLS/$USER.pem
echo committing everything
cd /data/per-user/$USER/backup/ cd /data/per-user/$USER/backup/
pwd
git add * git add *
git status
git commit -m"backup $USER @ `hostname` - `date`" git commit -m"backup $USER @ `hostname` - `date`"
if [ -e /data/per-user/$USER/backup/BACKUPDEST ]; then if [ -e /data/per-user/$USER/backup/BACKUPDEST ]; then
git pull --rebase git pull --rebase
......
#!/bin/sh
if [ $# -ge 2 ]; then
USER=$1
BACKUPDEST=$2
else
echo "Usage: sh ./scripts/backups-init.sh domain gitrepo"
exit 1
fi
echo "Adding backup job for $USER to $BACKUPDEST"
echo "First, trying to clone latest master from $BACKUPDEST"
git clone $BACKUPDEST /data/per-user/$USER/backup
sudo mkdir -p /data/per-user/$USER/backup
sudo echo "$BACKUPDEST" > /data/per-user/$USER/backup/BACKUPDEST
echo initializing backups for $USER
mkdir -p /data/per-user/$USER/backup/mysql
mkdir -p /data/per-user/$USER/backup/www
mkdir -p /data/per-user/$USER/backup/TLS
cd /data/per-user/$USER/backup/
git config --local user.email "backups@`hostname`"
git config --local user.name "`hostname` hourly backups"
git config --local push.default simple
if [ -e /data/per-user/$USER/backup/.git ]; then
git init
fi
echo "backups of $USER at IndieHosters server `hostname`" > README.md
git add README.md
git commit -m"initial commit"
echo "Pushing initial commit to $BACKUPDEST master branch"
cd /data/per-user/$USER/backup/
git remote add destination $BACKUPDEST
git push -u destination master
...@@ -4,12 +4,10 @@ Description=%p-%i ...@@ -4,12 +4,10 @@ Description=%p-%i
# Requirements # Requirements
Requires=docker.service Requires=docker.service
Requires=%p-importer@%i.service Requires=%p-importer@%i.service
Requires=%p-dump@%i.timer
# Dependency ordering # Dependency ordering
After=docker.service After=docker.service
After=%p-importer@%i.service After=%p-importer@%i.service
Before=%p-dump@%i.timer
[Service] [Service]
Restart=always Restart=always
......
...@@ -6,6 +6,7 @@ Requires=docker.service ...@@ -6,6 +6,7 @@ Requires=docker.service
Requires=%p-importer@%i.service Requires=%p-importer@%i.service
Requires=%p-discovery@%i.service Requires=%p-discovery@%i.service
Requires=%p-gitpuller@%i.path Requires=%p-gitpuller@%i.path
Requires=backup@%i.timer
# Dependency ordering # Dependency ordering
After=docker.service After=docker.service
......
...@@ -7,6 +7,7 @@ Requires=etcd.service ...@@ -7,6 +7,7 @@ Requires=etcd.service
Requires=mysql@%i.service Requires=mysql@%i.service
Requires=%p-importer@%i.service Requires=%p-importer@%i.service
Requires=%p-discovery@%i.service Requires=%p-discovery@%i.service
Requires=backup@%i.timer
# Dependency ordering # Dependency ordering
After=docker.service After=docker.service
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment