diff --git a/importers/backup-snapshot.sh b/importers/backup-snapshot.sh index aad02b4..2472dcb 100755 --- a/importers/backup-snapshot.sh +++ b/importers/backup-snapshot.sh @@ -1,38 +1,38 @@ #!/bin/bash -eux -if [ -e /data/per-user/$USER/mysql ]; then - echo backing up mysql databases for $USER - mkdir -p /data/per-user/$USER/backup/mysql/ - cp /data/per-user/$USER/mysql/.env /data/per-user/$USER/backup/mysql/.env - /usr/bin/docker run --link mysql-$USER:db\ - --env-file /data/per-user/$USER/mysql/.env \ +if [ -e /data/per-user/$DOMAIN/mysql ]; then + echo backing up mysql databases for $DOMAIN + mkdir -p /data/per-user/$DOMAIN/backup/mysql/ + cp /data/per-user/$DOMAIN/mysql/.env /data/per-user/$DOMAIN/backup/mysql/.env + /usr/bin/docker run --link mysql-$DOMAIN:db\ + --env-file /data/per-user/$DOMAIN/mysql/.env \ indiehosters/mysql mysqldump --all-databases --events -u admin \ - -p$(cat /data/per-user/$USER/mysql/.env | cut -d'=' -f2) \ - -h db > /data/per-user/$USER/backup/mysql/dump.sql + -p$(cat /data/per-user/$DOMAIN/mysql/.env | cut -d'=' -f2) \ + -h db > /data/per-user/$DOMAIN/backup/mysql/dump.sql fi -if [ -e /data/per-user/$USER/wordpress ]; then - echo backing up www from wordpress for $USER - mkdir -p /data/per-user/$USER/backup/www/ - rsync -r /data/per-user/$USER/wordpress /data/per-user/$USER/backup/www/wordpress +if [ -e /data/per-user/$DOMAIN/wordpress ]; then + echo backing up www from wordpress for $DOMAIN + mkdir -p /data/per-user/$DOMAIN/backup/www/ + rsync -r /data/per-user/$DOMAIN/wordpress /data/per-user/$DOMAIN/backup/www/wordpress fi -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 +if [ -e /data/per-user/$DOMAIN/nginx ]; then + echo backing up www from nginx for $DOMAIN + mkdir -p /data/per-user/$DOMAIN/backup/www/nginx/ + if [ -e /data/per-user/$DOMAIN/nginx/data/GITURL ]; then + cp /data/per-user/$DOMAIN/nginx/data/GITURL /data/per-user/$DOMAIN/backup/www/nginx/GITURL else - rsync -r /data/per-user/$USER/nginx/data/www-content /data/per-user/$USER/backup/www/nginx/www-content + rsync -r /data/per-user/$DOMAIN/nginx/data/www-content /data/per-user/$DOMAIN/backup/www/nginx/www-content 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 +mkdir -p /data/per-user/$DOMAIN/backup/TLS/ +cp /data/server-wide/haproxy/approved-certs/$DOMAIN.pem /data/per-user/$DOMAIN/backup/TLS/$DOMAIN.pem echo committing everything -cd /data/per-user/$USER/backup/ +cd /data/per-user/$DOMAIN/backup/ pwd git add * git status @@ -41,8 +41,8 @@ git config --local user.email "backups@`hostname`" git config --local user.name "`hostname` hourly backups" git config --local push.default simple -git commit -m"backup $USER @ `hostname` - `date`" -if [ -e /data/per-user/$USER/backup/BACKUPDEST ]; then +git commit -m"backup $DOMAIN @ `hostname` - `date`" +if [ -e /data/per-user/$DOMAIN/backup/BACKUPDEST ]; then git pull --rebase git push fi diff --git a/importers/mysql.sh b/importers/mysql.sh index 74e46e8..b0aac26 100755 --- a/importers/mysql.sh +++ b/importers/mysql.sh @@ -1,6 +1,6 @@ #!/bin/bash -eux -if [ ! -d "/data/per-user/$USER/mysql/data" ]; then - mkdir -p /data/per-user/$USER/mysql/data - echo MYSQL_PASS=`echo $RANDOM ${date} | md5sum | base64 | cut -c-10` > /data/per-user/$USER/mysql/.env +if [ ! -d "/data/per-user/$DOMAIN/mysql/data" ]; then + mkdir -p /data/per-user/$DOMAIN/mysql/data + echo MYSQL_PASS=`echo $RANDOM ${date} | md5sum | base64 | cut -c-10` > /data/per-user/$DOMAIN/mysql/.env fi diff --git a/importers/nginx.sh b/importers/nginx.sh index ebd69e9..996606f 100755 --- a/importers/nginx.sh +++ b/importers/nginx.sh @@ -1,11 +1,11 @@ #!/bin/bash -eux -if [ ! -e "/data/per-user/$USER/nginx/data/www-content/index.html" ]; then - if [ -e "/data/per-user/$USER/nginx/data/GITURL" ]; then - git clone `cat /data/per-user/$USER/nginx/data/GITURL` /data/per-user/$USER/nginx/data/www-content - cd /data/per-user/$USER/nginx/data/www-content && git checkout master +if [ ! -e "/data/per-user/$DOMAIN/nginx/data/www-content/index.html" ]; then + if [ -e "/data/per-user/$DOMAIN/nginx/data/GITURL" ]; then + git clone `cat /data/per-user/$DOMAIN/nginx/data/GITURL` /data/per-user/$DOMAIN/nginx/data/www-content + cd /data/per-user/$DOMAIN/nginx/data/www-content && git checkout master else - mkdir -p /data/per-user/$USER/nginx/data/www-content - echo Hello $USER > /data/per-user/$USER/nginx/data/www-content/index.html + mkdir -p /data/per-user/$DOMAIN/nginx/data/www-content + echo Hello $DOMAIN > /data/per-user/$DOMAIN/nginx/data/www-content/index.html fi fi diff --git a/importers/wordpress.sh b/importers/wordpress.sh index fc8c070..65f799b 100755 --- a/importers/wordpress.sh +++ b/importers/wordpress.sh @@ -1,8 +1,8 @@ #!/bin/bash -eux -if [ ! -d "/data/per-user/$USER/wordpress/data" ]; then - cd /data/per-user/$USER/ +if [ ! -d "/data/per-user/$DOMAIN/wordpress/data" ]; then + cd /data/per-user/$DOMAIN/ tar xvzf /data/indiehosters/blueprints/wordpress.tgz fi -cat /data/per-user/$USER/mysql/.env | sed s/MYSQL_PASS/DB_PASS/ > /data/per-user/$USER/wordpress/.env +cat /data/per-user/$DOMAIN/mysql/.env | sed s/MYSQL_PASS/DB_PASS/ > /data/per-user/$DOMAIN/wordpress/.env diff --git a/scripts/backup-init.sh b/scripts/backup-init.sh index b24021b..27f5c0f 100755 --- a/scripts/backup-init.sh +++ b/scripts/backup-init.sh @@ -1,36 +1,36 @@ #!/bin/sh if [ $# -ge 2 ]; then - USER=$1 + DOMAIN=$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 "Adding backup job for $DOMAIN to $BACKUPDEST" echo "First, trying to clone latest master from $BACKUPDEST" -git clone $BACKUPDEST /data/per-user/$USER/backup +git clone $BACKUPDEST /data/per-user/$DOMAIN/backup -sudo mkdir -p /data/per-user/$USER/backup -sudo echo "$BACKUPDEST" > /data/per-user/$USER/backup/BACKUPDEST +sudo mkdir -p /data/per-user/$DOMAIN/backup +sudo echo "$BACKUPDEST" > /data/per-user/$DOMAIN/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/ +echo initializing backups for $DOMAIN +mkdir -p /data/per-user/$DOMAIN/backup/mysql +mkdir -p /data/per-user/$DOMAIN/backup/www +mkdir -p /data/per-user/$DOMAIN/backup/TLS +cd /data/per-user/$DOMAIN/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 +if [ -e /data/per-user/$DOMAIN/backup/.git ]; then git init fi -echo "backups of $USER at IndieHosters server `hostname`" > README.md +echo "backups of $DOMAIN 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/ +cd /data/per-user/$DOMAIN/backup/ git remote add destination $BACKUPDEST git push -u destination master diff --git a/unit-files/backup@.service b/unit-files/backup@.service index 1527005..134e803 100644 --- a/unit-files/backup@.service +++ b/unit-files/backup@.service @@ -3,5 +3,5 @@ Description= Back up mysql and www data to a git repo and optionally push it out [Service] Type=oneshot -Environment=USER=%i +Environment=DOMAIN=%i ExecStart=/data/indiehosters/importers/backup-snapshot.sh diff --git a/unit-files/mysql-importer@.service b/unit-files/mysql-importer@.service index d6787b7..806d674 100644 --- a/unit-files/mysql-importer@.service +++ b/unit-files/mysql-importer@.service @@ -10,7 +10,7 @@ BindsTo=mysql@%i.service [Service] Type=oneshot RemainAfterExit=yes -Environment=USER=%i +Environment=DOMAIN=%i ExecStart=/data/indiehosters/importers/mysql.sh [Install] diff --git a/unit-files/nginx-importer@.service b/unit-files/nginx-importer@.service index 9bec231..4dd4ce0 100644 --- a/unit-files/nginx-importer@.service +++ b/unit-files/nginx-importer@.service @@ -10,7 +10,7 @@ BindsTo=mysql@%i.service [Service] Type=oneshot RemainAfterExit=yes -Environment=USER=%i +Environment=DOMAIN=%i ExecStart=/data/indiehosters/importers/nginx.sh [Install] diff --git a/unit-files/wordpress-importer@.service b/unit-files/wordpress-importer@.service index fb0b2c7..9215484 100644 --- a/unit-files/wordpress-importer@.service +++ b/unit-files/wordpress-importer@.service @@ -11,7 +11,7 @@ BindsTo=wordpress@%i.service [Service] Type=oneshot RemainAfterExit=yes -Environment=USER=%i +Environment=DOMAIN=%i ExecStart=/data/indiehosters/importers/wordpress.sh [Install]