Plug-And-Play backup container that works with recent versions of Ghost's official Docker images.
546
ghost-backup is a simple, automated, backup (and restore) Docker container for a Ghost blog. It supports Ghost configured with either sqlite or mysql/mariadb.
By default it will create a backup of the ghost content files (images, themes, apps, config.js) and the database (actual posts) daily at 3am, keeping the most recent 30 backups.
Ghost uses sqlite by default, if you have not changed the configuration to mysql.
Create and run the ghost-backup container with the volumes from your Ghost data container:
docker run --name ghost-backup -d --volumes-from <your-data-container> bennetimo/ghost-backup
Where:
<your-data-container> is either your Ghost blog container, or a separate data-only container holding your blog files. Basically, wherever your blog content lives.
That's it! This will create and run a container named 'ghost-backup' which will create a backup of your Ghost database and content files under /backups every day at 3am.
See below sections for customizing the backup.
If your Ghost configuration is using mysql/mariadb then you just need to link in your mysql container when you create the backup container:
docker run --name ghost-backup -d --volumes-from <your-data-container> --link <your-mysql-container>:mysql bennetimo/ghost-backup
Where:
<your-data-container> is as above
<your-mysql-container> is your mysql/mariadb database container for your blog
The linked mysql container needs to have the alias 'mysql' as shown.
The following environment variables should be set on the mysql container. ghost-backup will pick them up automatically through container linking so it can talk to the database:
docker exec ghost-backup backup
This will create an immediate backup. You should now have two archives created in the backup folder (/backups by default). One archive is the database, the other the ghost content files.
Note that backups are are tagged with the date and time in the form yyyymmdd-hhmm, therefore if two backups are created in the same minute then the second will overwrite the first.
A backup is no good if it can't be restored :) You can do that in three ways:
You can launch an interactive backup menu using:
docker exec -it ghost-backup restore -i
This will display a menu with all of the available backup files. You can select which to restore by number or name.
Using interactive backup you can restore a DB archive separately to a Ghost files archive
You can also restore by date:
`docker exec ghost-backup restore -d yyyymmdd-hhmm This will restore the backup files (database and content) from yyyymmdd-hhmm, if found.
You can restore a given file mounted to the container:
docker exec ghost-backup restore -f /path/to/file/filename
Ghost restore will treat filenames containing 'db' as database files, and filenames containing 'ghost' as archive files.
By default the restore script will remove the ghost files from GHOST_LOCATION before restoring the archive, except for the database which is handled separately.
To restore without removing files first you can specificy the command argument capitalised, e.g. -I, -D, -F.
ghost-backup has a number of options which can be configured as you need.
| Environment Variable | Default | Meaning |
|---|---|---|
| BACKUP_TIME | "0 3 * * *" | A cron expression controlling the backup schedule. |
| BACKUP_LOCATION | "/backups" | Where the backups are written to |
| BACKUPS_RETAIN_LIMIT | 30 | How many backups to keep. Oldest are removed first |
| LOG_LOCATION | "/var/log/ghost-backup.log" | Location of the log file |
| GHOST_LOCATION | "/var/lib/ghost" | Location of ghost content and db files |
For example, if you wanted to backup at 2AM to the location /some/dir/backups, storing 10 days of backups you would use:
docker run --name ghost-backup -d --volumes-from <your-data-container> -e "BACKUP_LOCATION=/some/dir/backups" -e "BACKUP_TIME=0 2 * * *" -e "BACKUPS_RETAIN_LIMIT=10" bennetimo/ghost-backup
This example is for Ghost using sqlite. If you're using mysql/mariadb just add the linked mysql containers as described above.
By default, the backup will have a Ghost files archive, a DB archive, and purge any excess old backups specified by the BACKUPS_RETAIN_LIMIT. Each of these can be disabled with command arguments:
For example to perform a backup of just the DB with no purge:
docker exec ghost-backup backup -FP
You can configure the backup location as you wish, which if used in conjunction with bennetimo/docker-dropbox will backup to a Dropbox folder.
To do this, you need to have a dropbox container running, linked to your account:
docker run -d --name dropbox bennetimo/docker-dropbox
You need to link this container to your Dropbox account first, see docker-dropbox quickstart
Then create your backup container using the Dropbox volume:
docker run --name ghost-backup -d --volumes-from <your-data-container> --volumes-from <your-dropbox-container> -e "BACKUP_LOCATION=/root/Dropbox" bennetimo/ghost-backup
That's it. Now if your Dropbox container has been linked correctly to your account you'll have a backup of your blog added every day at 3am to your Dropbox.
docker logs ghost-backup
Will display logs of all of backup runs (manual and automated) and restore operations. By default the log file is at: /var/log/ghost-backup.log
If you want to disable automated backups and just perform them manually as necessary, then you can stop the crontab installation by starting your container as:
docker run -d --name ghost-backup --volumes-from <your-data-container> -e "AUTOMATED_BACKUPS=false" ghost-backup
Now you can run:
docker exec ghost-backup backup
Every time you want to take a backup. You can restore as normal (described above).
You can use ghost-backup to create a local test environment for your blog, with all the posts and content.
When using sqlite, the backup/restore is handled using the command line shell of the online backup API.
When using mysql/mariadb, the backup/restore is handled using mysqldump. You should use InnoDB tables for online backup.
This container was inspired by wordpress-backup
Content type
Image
Digest
Size
88 MB
Last updated
about 8 years ago
docker pull rija/ghost-backup