Scripts for managing my hosting on ostankin.net.
Sites are routed via Nginx. Each site is configured in a separate file under
nginx.conf directory. Each site may be:
- a static file tree, each located in a separate directory under
- a CMS, represented by a CMS container, linked to MySQL database container.
Both CMS and database are persistent and stored in
.data/db directories respectively.
The setup requires Docker and Docker Compose to work (as
apt-get install docker docker.io python-pip pip install docker-compose
The following elements are responsible for hosting configuration:
backup- a location for backup files;
config.d- metadata for CMS sites;
nginx.conf- set of Nginx config files for each site;
docker-compose.yml- configuration of containers and their interdependencies.
Restoring from backup
Static sites do not need any complex backup-restore mechanisms,
rsync is just enough to keep them safe. CMS'es need more attention.
There are two ways to restore a CMS-site:
- rebuild the whole hosting from scratch, using site backups;
- restore from backup a single site.
It is assumed that there is a
with the following two files(for each site):
<site_name>_db.sql.gz- gzipped database dump (prefix not used);
<site_name>_files.tar.gz- archived (with -p key!) CMS files.
Rebuilding the whole hosting from scratch
./restore-from-backup -a does the following:
- Stops all containers (if they are running).
- Unpacks the backup files and prepares them for deployment.
.datadirectory, thus destroying all current data.
- Deploys the backup data.
- Generates new database passwords and updates the CMS configs.
- Starts new containers.
- Restores the databases from backup and creates users to access them.
Restoring a single CMS site
./restore-from-backup <site_name> does the following:
- Wipes the existing CMS files.
- Restores CMS files from backup.
- Recreates the corresponding database.
Since passwords are not recreated, the script does not allow restoring from backups, created before the whole rebuild was done (and new passwords were generated).
Creating a backup
./create-backup does the following:
- Takes a snapshot of each CMS site database.
- Creates a tarball from all CMS files for each site separately.
- Puts backup files into