Created
December 4, 2018 15:32
-
-
Save mikeggrant-eumetsat/660772f011e88e161c748691558972a0 to your computer and use it in GitHub Desktop.
systemd unit files for backing up the mongo database of a standard rocket.chat docker install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Run a backup-dump of the mongo database in the mongo docker container | |
Requisite=mongo.service | |
After=mongo.service | |
[Service] | |
Type=oneshot | |
User=root | |
# have to escape the %s or systemd replaces them | |
ExecStart=/bin/docker exec -t mongo bash -c 'mongodump --archive=/data/dump/$(date +%%Y%%m%%d%%H%%M%%S).gz --gzip' | |
# notify #rocket-admin channel that the backup worked | |
# N.B. need to update the host and hook token in the URL part | |
ExecStartPost=/bin/bash -c 'curl --insecure --silent -X POST -H \'Content-Type: application/json\' --data \'{"text":"Backup to %H:/data/mongo/dump/ completed successfully"}\' https://HOST/hooks/WEBHOOKKEY | grep --quiet \'^{"success":true}$\'' | |
# delete all but 14 most recent backups (double % for escaping systemd replacements) | |
ExecStartPost=/bin/bash -c "echo 'Mongo backup completed; removing excess backups..' ; find /data/mongo/dump/ -type f -printf '%%T@ %%p\n' | sort --reverse --numeric | tail --lines +14 | cut --fields 2 --delimiter=' ' | xargs --no-run-if-empty rm -fv" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=mongo backup timer | |
[Timer] | |
OnCalendar=daily |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=rocketchat | |
Requires=docker.service | |
Requires=httpd.service | |
Requires=mongo.service | |
Requires=mongo-backup.timer | |
After=docker.service | |
After=mongo.service | |
[Install] | |
WantedBy=multi-user.target | |
....... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment