Backup Docker Installation #1132
-
Hi, what is the best way to backup the Data for a possible restore? Is it enough to backup the 3 Data-Volumes? thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 5 replies
-
I am trying wo wrap my head around this too at the moment. It is easy to backup the postgres db, but it seems to be more tricky to backup the clickhouse db. Do we even need to backup the geoip database as it can just be redownloaded without losing any sensible information or analytics data? Anybody knows of a good approach on how to backup and restore plausible running in the official docker environment? |
Beta Was this translation helpful? Give feedback.
-
Anyone else tried some things? I suppose the Postgres can be backed up by dumping all the tables into a file. I might experiment with this later on. |
Beta Was this translation helpful? Give feedback.
-
Hello there, here is what i did to move all the plausible data from one Server to another.
For more information consult the documentation at https://github.com/loomchild/volume-backup. my scripts:
I hope this helps :) |
Beta Was this translation helpful? Give feedback.
-
I self-host Plausible on Kubernetes and wrote DB-level backup scripts that I run daily against Plausible using cron. Restore scripts are also available: https://github.com/schnerring/k8s-backup-scripts The scripts aren't really applicable to Use backup_postgres() {
echo "Backing up Postgres ..."
pod=$(get_pod_name "${POSTGRES_LABEL}" "${POSTGRES_NAMESPACE}")
kubectl exec -i -n "${POSTGRES_NAMESPACE}" "$pod" -- \
pg_dump -Fc "${PLAUSIBLE_DB}" >"${PLAUSIBLE_BACKUP_DIR}/$(date +%y%m%d)-postgres-${PLAUSIBLE_DB}.dump"
} Use backup_clickhouse() {
echo "Backing up ClickHouse ..."
mkdir -p "${PLAUSIBLE_BACKUP_DIR}"
install_clickhouse_backup
backup_name=$(date +%y%m%d)-clickhouse
echo "Creating backup ${backup_name} ..."
pod=$(get_pod_name "${PLAUSIBLE_EVENT_DATA_LABEL}" "${PLAUSIBLE_NAMESPACE}")
kubectl exec -i -n "${PLAUSIBLE_NAMESPACE}" "$pod" -- \
clickhouse-backup create "${backup_name}"
tmp="${PLAUSIBLE_BACKUP_DIR}/tmp"
pod_path="${PLAUSIBLE_NAMESPACE}/${pod}:/var/lib/clickhouse/backup/${backup_name}"
echo "Copying ${pod_path} to ${tmp} ..."
kubectl cp "${pod_path}" "${tmp}"
backup_destination_path="${PLAUSIBLE_BACKUP_DIR}/${backup_name}.tar.gz"
echo "Compressing ${backup_destination_path} to ${tmp} ..."
tar -zcf "${backup_destination_path}" -C "${tmp}" .
echo "Cleaning up ..."
rm -rf "${tmp}"
kubectl exec -i -n "${PLAUSIBLE_NAMESPACE}" "$pod" -- \
clickhouse-backup delete local "${backup_name}"
} The restore script just reverts the above logic. Keep in mind that you need to manually restore the EDIT: as of ClickHouse v23 and clickhouse-backup v2, tables other than MergeTree are now also supported INSERT INTO plausible.schema_migrations (version,inserted_at) VALUES
(20200915070607,'2022-04-22 04:07:40'),
(20200918075025,'2022-04-22 04:07:40'),
(20201020083739,'2022-04-22 04:07:40'),
(20201106125234,'2022-04-22 04:07:40'),
(20210323130440,'2022-04-22 04:07:40'); NOTE: the query depends on the Plausible version. The above query is for Plausible v1.4.4 |
Beta Was this translation helpful? Give feedback.
-
I wrote a tutorial some time ago in german: https://sewid-webdesign.de/blog/backup-und-restore-von-plausible-analytics |
Beta Was this translation helpful? Give feedback.
-
I didn't manage to back up the ClickHouse database using Here is a script that backs up both ClickHouse and PostgreSQL data to an S3 bucket: S3_REGION="eu-west-3"
S3_BUCKET="my-bucket-name"
TIMESTAMP=$(date '+%Y-%m-%d-%H%M')
docker compose exec -T plausible_events_db clickhouse-client --query "BACKUP ALL TO S3('https://s3.$S3_REGION.amazonaws.com/$S3_BUCKET/$TIMESTAMP/clickhouse/')"
docker compose exec -T plausible_db pg_dump -d plausible_db -U postgres -Fc | s3cmd put - s3://$S3_BUCKET/$TIMESTAMP/postgres.dump This script uses the |
Beta Was this translation helpful? Give feedback.
I self-host Plausible on Kubernetes and wrote DB-level backup scripts that I run daily against Plausible using cron. Restore scripts are also available:
https://github.com/schnerring/k8s-backup-scripts
The scripts aren't really applicable to
docker-compose
, but you can try to extract the important bits from the scripts and adjust them accordingly.Use
pg_dump
to backup Plausible DB:Use
clickhouse-backup
for …