k3s-minecraft icon indicating copy to clipboard operation
k3s-minecraft copied to clipboard

K3s server sqlite backup

Open adyanth opened this issue 2 years ago • 1 comments

For https://github.com/gilesknap/k3s-minecraft/tree/main/useful/deployed/backup-sqlite, I used the following for taking a backup.

  command:
    - /bin/sh
    - -c
    - apk add sqlite; cd /server; time tar czf /backup/k3s-server-backup-$(date +%F:%R).tgz --exclude *.sock --exclude db . && time sqlite3 db/state.db .dump | gzip -c > /backup/k3s-server-db-dump-$(date +%F:%R).gz && time sqlite3 db/state.db ".backup '/backup/k3s-server-db-backup-$(date +%F:%R).sql" && time find /backup -type f -mtime +60 -delete;

This takes two types of sqlite backup, one a SQL dump, another a DB page by page backup. I am not sure if the drastic decrease in size after restoring the .dump version is actually correct. So, to be on the safer side, I am doing both forms of backups and raised an issue at https://github.com/k3s-io/k3s/issues/5219

To restore,

cd /var/lib/rancher/k3s; mv server server.old; mkdir -p server/db; cd server
tar -xzf k3s-server-backup-XXX.tgz

zcat k3s-server-db-dump-XXX.gz | sqlite3 db/state.db
# OR
cp k3s-server-db-backup-XXX.db db/state.db

adyanth avatar Mar 07 '22 19:03 adyanth

Hey thanks! I was just looking at why my current backups were failing and this came in at the same time. I'm aware that my current approach may backup the DB in a inconsistent state.

I'll give your approach a go, it looks good.

gilesknap avatar Mar 07 '22 19:03 gilesknap