Setting up Backblaze with Restic (Windows 10)

Hi, I am very new to Restic. I have a Backblaze bucket and application key ready to receive back ups.

I was following Backblaze’s tutorial on configuring Restic to work with it (focused for Linux and MacOS), and I’m stuck on a few things.

For example:
Defining the restic environment variables:

  • I am not sure where I can find B2_ACCOUNT_ID or B2_ACCOUNT_KEY.
  • I am not sure if RESTIC_REPOSITORY is the exact name of my bucket that will be the repository.
  • I am not sure if RESTIC_PASSWORD_FILE’s file path has to be the FULL file path to the file or if it can be abbreviated.

I am also unsure of what the equivalent of “source ~/restic-env” is for Windows.

Apologies for the loaded questions, but most of the tutorials I’ve seen online are primarily geared towards Linux.

it is very simple:

RESTIC_REPOSITORY is the name of your b2-bucket.
ID and KEY are the keys from backblaze. as far as i remember, one of them is only shown once when you create the bucket. i also setup cache and tmp-dir, in case of /tmp is to small.

export RESTIC_PASSWORD=123456
export RESTIC_REPOSITORY='b2:yourBucketName:/' 
export B2_ACCOUNT_ID='......' 
export B2_ACCOUNT_KEY='......' 
export RESTIC_CACHE_DIR=/backup/restic.cache 
export TMPDIR=/backup/restic.tmp

it is very simple:

RESTIC_REPOSITORY is the name of your b2-bucket.
ID and KEY are the keys from backblaze. as far as i remember, one of them is only s

export RESTIC_PASSWORD=123456
export RESTIC_REPOSITORY=‘b2:yourBucketName:/’
export B2_ACCOUNT_ID=‘…’
export B2_ACCOUNT_KEY=‘…’
export RESTIC_CACHE_DIR=/backup/restic.cache
export TMPDIR=/backup/restic.tmp

Is this in Linux/Bash syntax? Would this work in Windows or does this requiring tinkering first?

Yes, this example is for Linux Systems. I just did a quick “Windows Restic backup” Google search and got shown some GitHub projects where others have offered their Powershell script which they use to fully automate their backup.

On Windows you can see the documentation here: set (environment variable)

But it is as simple as

set RESTIC_REPOSITORY="C:/whatever"

if you do it in a cmd window.

If you would like a PowerShell script, then it’s a different syntax. You have to read up on how that works or browse the forum for Windows related topics. I bet there are various threads that will help you out.

yes it is. but the main point is, setting up environments vars. this differs in linux, windows. but in the end it is only about environment vars.

Hi sorry for the late response. I do not have access to my PC this week, so I am unable to experiment with your suggestion.

To clarify, in CMD, with path c:/Users/Saki/Etc, I set my variables using SET?

Does it generate a file? The Back Blaze doc mentioned a restic-env file, which gets referenced when the repo is initialized.

I’m just trying to break this down in easy to digest infallible steps.

Yea that’s what it seems like. Setting the variables.

Do I just type them all one by one in CMD? Hit Enter after each?

hi, can do that but better to put all the commands into a simple text file.

can create a text file with .cmd extension.

here is a simple example file, called var.cmd
note: need to change the values to match your setup

set RESTIC_REPOSITORY="b2:restic-west02"
set RESTIC_PASSWORD=password
set B2_ACCOUNT_ID=012x11f5584568299998888zz
set B2_ACCOUNT_KEY=K012eFG6971Sshi/qrSSS897QC1dBfd

and from the command line, run the command var.cmd
now, when you run restic, it will use those parameters

so at this point, to create a new repo, is a simple as
restic init

In the Back Blaze documentation, they had:

SET RESTIC_PASSWORD_FILE=/etc/restic-password
instead of
set RESTIC_PASSWORD=password

I’d like to point my password to a file as well? How can I achieve this? Does the file need to be in the same directory as the .cmd file? Do I need the full file path?

i did changed that, to simply the number of steps for you.

so, if you want to use a password file,

  1. create a text file with the password only, no newline. let’s call it c:\path\to\pwd.file

and the var.cmd would look like

set RESTIC_REPOSITORY="b2:restic-west02"
set RESTIC_PASSWORD_FILE=c:\path\to\pwd.file
set B2_ACCOUNT_ID=012x11f5584568299998888zz
set B2_ACCOUNT_KEY=K012eFG6971Sshi/qrSSS897QC1dBfd

Can the password be stored in a .txt file?

yes, as the name of the file does not matter.

Gotcha, just got a few more questions:

  1. This is the password I am making up for my repo, yes?
  2. Does RESTIC_REPOSITORY have to be "b2:restic-west02"? Or is it the name of my B2 Bucket?
  3. I run this CMD file through command line, and then restic init ? How do I “connect” this CMD file to the repo I’m trying to init?

For example, I name my CMD file "saki-restic-var.cmd", how do I init my repo using this CMD?

Thanks in advance.

  1. yes
  2. the name of your bucket. i did a copy/paste from the b2 weblink you posted.
  3. a basic convenience feature of most programs.

var.cmd loads the variables into the command line, so you do not have to type it all manually.

each time restic starts, it looks for certain environment variables and uses them with the restic command as defaults.

for example, restic looks for B2_ACCOUNT_ID and if found, use the value from var.cmd
which in our case is 012x11f5584568299998888zz

You mean it by default looks for my bucket variable? What if I had a 2nd bucket, and wanted to create a second routine that backed up different files?

Do I have to SET a different group of variables? When I init a second repo for that 2nd bucket, how does it not get the first group of variables mixed up from the second group?

I guess I’m just having a hard time understanding the proper steps:
I guess it would be like

  • C:\Windows\system32>Saki-Restic-Variables-1.cmd
  • C:\Windows\system32>restic init

Did I get it right?

And if I want a 2nd repo in a 2nd bucket, it’s

  • C:\Windows\system32>Saki-Restic-Variables-2.cmd
  • C:\Windows\system32>restic init

yes

bingo.

i think you got it all figured out now.

But how does the 2nd restic init know to use the variables that created in Saki-Restic-Variables-2.cmd?

As in the id, key, and name of that second bucket? There doesn’t seem to be a parameter to choose which bucket you’re targeting. Does Windows just magically know?

Is it because I invoked the .cmd file right before the initialization and it just takes the variables from the last thing I invoked?

that is correct.

Looks like I made a typo in my repo variable. Is that a problem? Do I need to UNSET anything or delete something from environment variables?

Or can I just close my command line window, edit my file, and try again?

no requirement to close the terminal.
tho that is always a good, safe way to prevent mistakes.

  1. fix the typo in Saki-Restic-Variables-1.cmd
  2. open a new command prompt.
  3. run Saki-Restic-Variables-1.cmd
  4. run restic init or whatever restic command(s) you choose.