A Docker-based tool for creating and managing backups of your LocalCrag database and MinIO storage.
-
Clone the repository:
git clone https://github.com/LocalCrag/LocalCragBackup.git cd LocalCragBackup -
Copy the
config.template.ymlfile toconfig.yml:cp config.template.yml config.yml
-
Update the config.yml file with your setup details
- You can choose between storing backups locally or on an SFTP server.
- Add an email configuration to receive notifications about backup errors
For the backup tool to be able to access your deployments database and MinIO storage, you need to ensure that the database is accessible from the server where the backup tool is running. The MinIO storage should already be accessible via the endpoint that the LocalCrag deployment is using (normally smth like https://s3.your-domain.com).
To make the database accessible, follow these steps:
- Create a
pg_hba.conffile in the root directory of your LocalCrag deployment with the following content:Replace# Allow access from the backup tool's IP address host all backup <BACKUP_TOOL_IP>/32 md5<BACKUP_TOOL_IP>with the actual IP address of the server where the backup tool will run. - Create a
docker-compose.override.ymlfile to open the database port of your LocalCrag deployment and mount thepg_hba.conffile to allow access from the backup tool's IP address. Also add thePOSTGRES_BACKUP_PASSWORDenvironment variable to the server service. On server startup, the backup postgres user will be created using this password.services: database: ports: - 5432:5432 volumes: - database:/var/lib/postgresql/data/db-files # Needed in the override file as well as lists get replaced, not merged - ./pg_hba.conf:/var/lib/postgresql/data/pg_hba.conf server: environment: POSTGRES_BACKUP_PASSWORD: secure-password-for-backup-user
- Restart your LocalCrag deployment to apply the changes:
docker compose down docker compose up -d
- Open the port in your firewall to allow access to the database from the backup tool's IP address. For example, if you are using
ufw, you can run:sudo ufw allow from <BACKUP_TOOL_IP> to any port 5432
To run the backup script, use the following command (expects to be run from the root directory of the LocalCragBackup repository, replace $(pwd) with the path to your LocalCragBackup directory if needed):
docker run --rm -v $(pwd)/backups:/app/backups -v $(pwd)/config.yml:/app/config.yml ghcr.io/localcrag/localcrag-backup:latestThe script will create a backup of your database and MinIO storage, storing the files in the configures backup directory. It is recommended to run this script periodically (e.g. in cron), such as daily or weekly, to ensure you have up-to-date backups.
Note: The minio mc tool has a weird behaviour where it will fail with mc: <ERROR> Unable to prepare URL for copying. Unable to guess the type of copy operation. if the bucket is empty. If you get this error when setting up backups a fresh LocalCrag instance, you can work around it by e.g. setting a profile picture for your superadmin account.