Ghost Blog, Part Three
Man, I am feeling like I am spinning my wheels on this project lately. So things that need to be backed up are the content
folder of Ghost, they kindly place everything you need in there. Then I'd need a backup of my docker-compose.yml
file. Finally I'll need to take a database dump. Since the image is using MySQL that should be pretty easy. I think it would look something like this:
docker exec -it ghost_db_1 sh mysqldump -u root ghost > /var/lib/mysql/ghost-`date +%F`.sql
Let's test this out.
Steps performed on DOCKER-01
docker exec -it ghost_db_1 sh
mysqldump -u root ghost > /var/lib/mysql/ghost-
date +%F.sql
mysql: Got error: 1045: Access denied for user 'root'@'localhost' (using password: NO) when trying to connect
mysqldump -u root -pPassword ghost > /var/lib/mysql/ghost-`date +%F`.sql
Success! Now the only trouble is the fact that the password is just sitting there in the command. What can I do about that? Well I can access my dump on the host located at /var/lib/docker/volumes/ghost_db/_data
. So I can put a .mysql-cred
file in there to store the password. So that would change my command to:
mysqldump --default-extra-file=/var/lib/mysql/.mysql-cred -u root ghost > /var/lib/mysql/ghost-`date +%F`.sql
Testing this inside the container is successful. So now I need to test it via docker exec
:
docker exec -it ghost_db_1 sh -c "mysqldump --defaults-extra-file=/var/lib/mysql/.mysql-cred -u root ghost > /var/lib/mysql/ghost-`date +%F`.sql
Awesome it's working!
mkdir /home/david/Backups/Ghost
mkdir /home/david/Backups/Ghost/Archive
sudo nano /usr/bin/ghost-backup
sudo chmod +x /usr/bin/ghost-backup
sudo nano /etc/crontab
# Script to backup the Ghost application for davidbuhlman.com
15 0 * * 5 root /usr/bin/ghost-backup
- I saved
crontab
There we go, the site is up and running, along with it's backups. Super exciting!