compose-website/unit-files/backup@.service

34 lines
938 B
SYSTEMD
Raw Normal View History

2014-11-04 14:27:07 +00:00
[Unit]
2014-11-05 12:43:16 +00:00
Description=Back up domain data to a git repo and push it out
2014-11-04 14:27:07 +00:00
[Service]
Type=oneshot
2014-12-03 17:08:51 +00:00
ExecStartPre=-/usr/bin/docker kill mysqldump-%i
ExecStartPre=-/usr/bin/docker rm mysqldump-%i
2014-11-05 12:43:16 +00:00
ExecStartPre=/bin/bash -euxc ' \
2014-11-05 17:28:04 +00:00
if [ -d /data/domains/%i/mysql ]; then \
echo "Backing up mysql databases for %i"; \
mysql_passwd=`cat /data/domains/%i/mysql/.env | cut -d= -f2`; \
2014-11-05 12:43:16 +00:00
/usr/bin/docker run \
2014-12-03 17:08:51 +00:00
--rm \
--name mysqldump-%i \
2014-11-05 17:28:04 +00:00
--link mysql-%i:db \
--env-file /data/domains/%i/mysql/.env \
2015-01-05 16:35:46 +00:00
pierreozoux/mysql \
2014-11-05 12:43:16 +00:00
mysqldump \
--all-databases \
--events \
2014-12-03 17:08:33 +00:00
-uadmin \
2014-11-05 17:28:04 +00:00
-p$mysql_passwd \
-h db > /data/domains/%i/mysql/dump.sql; \
2014-11-05 12:43:16 +00:00
fi'
ExecStart=/bin/bash -euxc ' \
2015-01-14 13:43:12 +00:00
2014-11-05 12:43:16 +00:00
echo "Committing everything"; \
2014-11-05 17:28:04 +00:00
cd /data/domains/%i/; \
2014-11-05 12:43:16 +00:00
git add *; \
git status; \
2014-12-02 14:49:33 +00:00
git commit --allow-empty -am"backup %i @ `hostname` - `date`"; \
2014-12-02 14:49:25 +00:00
git push origin master'