Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K3s server sqlite backup #2

Open
adyanth opened this issue Mar 7, 2022 · 1 comment
Open

K3s server sqlite backup #2

adyanth opened this issue Mar 7, 2022 · 1 comment

Comments

@adyanth
Copy link

adyanth commented Mar 7, 2022

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 k3s-io/k3s#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
@gilesknap
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants