{"title":"Using Ostree for file snapshots","url":"https://seanbehan.ca/posts/ostree","description":"Ostree is not just for Silverblue. Using it as a content-addressed snapshot store for your own files.","author":"Sean Behan","published":"2023-05-27T11:47:26.000Z","updated":null,"draft":false,"tags":["backup","linux","ostree"],"readingMinutes":2,"image":null,"sections":[{"id":"introduction","text":"Introduction","level":2},{"id":"initializing-the-ostree-repository","text":"Initializing the Ostree Repository","level":2},{"id":"committing-and-restoring-files","text":"Committing and Restoring Files","level":2},{"id":"important-considerations","text":"Important Considerations","level":2}],"content_format":"text/markdown","content_url":"https://seanbehan.ca/posts/ostree.md","content":"### Introduction\n\nOstree is the software that allows rpm-ostree in Fedora Silverblue to keep snapshots of previous deployments and do incremental updates, but did you know it can also be used to keep snapshots of your own files? It's actually quite easy once it's all set up.\n\nFor this I would strongly suggest you use root for your ostree. Although you can use it without, you will be able to use files that regular users can't use such as hardlinks if you're root, which will speed up incremental snapshots very much.\n\n### Initializing the Ostree Repository\n\nFirst you'll want to create your inital ostree. Do this in a new folder, on a drive with lots of free space for the files you want to snapshot. You'll need as much free space as all the files you want to snapshot.\n\n```sh\nmkdir tree\nsudo ostree init --repo=tree\n```\n\n### Committing and Restoring Files\n\nNext you can start committing files to your new tree. Be sure to check the man pages for `ostree-commit` and `ostree-init`.\n\n```sh\nsudo ostree commit --repo=tree --branch=master $PWD/dir\n```\n\nKeep in mind you cannot commit individual files, only entire directories at a time. Now when you change something inside `/dir` you can commit again with the exact same command and you will have both copies in your ostree. To restore the original copy you can then use `ostree-checkout`.\n\n```sh\nostree refs --repo=tree master\n```\n\nThis will show you a list of all your commits. Now choose the one you want to restore.\n\n```sh\nostree checkout --repo=tree --union your-commit-sha dir\n```\n\n### Important Considerations\n\nMake sure you check `ostree -h` for a list of ostree commands and read each of their man pages if you want to use them fully.\n\nI use this on a filesystem that is already a RAID1. Make sure you keep proper backups, ostree can create snapshots but it won't help you if your entire drive fails.\n"}