Plausible Docker Volume Backup
Mar 18, 2025 Backup Written by Vivek Shukla
#!/bin/bash
home="/home/<update>/"
dest="<update>"
bucket="<update>"
pg_container_id="<update>"
ch_container_id="<update>"
passphrase="<update>"
date=$(date +"%Y%m%d%H%M%S")
pl_repo=$home"/"$date"_plausible.tar.gz"
pl_repo_gpg=$pl_repo".gpg"
pg_data=$home"/"$date"_db-data.tar.gz"
pg_data_gpg=$pg_data".gpg"
ch_data=$home"/"$date"_event-data.tar.gz"
ch_data_gpg=$ch_data".gpg"
# stopping postgres and clickhouse containers before backup
docker container stop $pg_container_id $ch_container_id
# creating gzip file
tar --exclude=images --exclude-vcs -czf $pl_repo -C $home plausible
sudo tar -czf $pg_data -C /var/lib/docker/volumes/ plausible_db-data
sudo tar -czf $ch_data -C /var/lib/docker/volumes/ plausible_event-data
# starting containers
docker container start $pg_container_id $ch_container_id
# encrypting
echo $passphrase | gpg --batch --yes --passphrase-fd 0 -o $pl_repo_gpg --symmetric $pl_repo
echo $passphrase | gpg --batch --yes --passphrase-fd 0 -o $pg_data_gpg --symmetric $pg_data
echo $passphrase | gpg --batch --yes --passphrase-fd 0 -o $ch_data_gpg --symmetric $ch_data
# saving to s3
rclone copy $pl_repo_gpg $dest:$bucket
rclone copy $pg_data_gpg $dest:$bucket
rclone copy $ch_data_gpg $dest:$bucket
# deleting local copies
rm -f $pl_repo $pg_data $ch_data
rm -f $pl_repo_gpg $pg_data_gpg $ch_data_gpg