Replaces USER with DOMAIN

This commit is contained in:
pierreozoux 2014-11-04 17:56:36 +00:00
parent 7eff7f4a19
commit 10dfb0f343
9 changed files with 52 additions and 52 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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]

View file

@ -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]