Personally I use a private Github repository for backing up my space. This is how I set this up.
Requirements
- A (free) Github account
- A private Github repository to keep your space files
Create a token
We will authenticate with Github via HTTPS and a personal access token. This is relatively safe and simple to setup.
Go to your Personal Access Tokens page, and Generate a new token (beta) scoped to your repository.
- Select a expiry date far in the future
- Select: “Only selected repositories” and select your private space repostiory.
- For permissions choose:
- Contents: Read & Write
Then generate the token. Save the token some place safe, you will need it later in a bit.
Get a shell
If you’re running SilverBullet directly on your machine using Deno, you can just cd
into your space folder and use git
from there (if it is installed, if not, install git first).
If you’re running inside of a docker container (or fly.io container) you need to get a shell into your container.
Using docker you can do this with docker exec
. For instance, if your container is named silverbullet
you can run:
docker exec -it silverbullet /bin/bash
If you’re deployed to fly.io, you can get a shell via
fly ssh console
Configure the git repository
In your shell:
# Change to the space folder, in docker this is always /space
cd /space
# Initialize it as a git repo
git init
# Configure your name and email
git config user.name "Your Name"
git config user.email "[email protected]"
# Set rebasing to false (or true if you prefer)
git config pull.rebase false
# Add the Github repository you created as a remote, replace GITHUBTOKEN with the token you received earlier
git remote add origin https://[email protected]/username/repo.git
Empty repository
If you created a fresh Github repository with no content yet, you can do the following:
# Set the branch to main
git branch -m main
# Add all existing files
git add *.md
# Commit the first version
git commit -m "Initial commit"
# Push the first version
git push origin main
Existing content
If your repository already has content, first clean out the auto generated files (index.md and SETTING.md), then checkout the remote branch:
# Fetch all branches from the remote repostiroy
git fetch
# Clean out the auto generated pages
rm index.md SETTINGS.md
# Checkout your main branch from the repository
git checkout main
Setting up the Git plug
Open up SilverBullet and run the Plugs: Add
command and enter github:silverbulletmd/silverbullet-git/git.plug.js
.
This will give you some useful Git: *
commands. Checkout the silverbullet-git README for more information, I specifically recommend you set up auto sync, to make backups automatic.
Enjoy!