Repository initialization is your first door into restic: `restic init` for local and S3 backends, using `--repository-file` to store the repo URL in a file, and managing the repository password securely via env, gpg, or a secret manager so your data never stays locked forever.

In episode 2 you understood the three-pillar architecture: repository, snapshot, and chunking. Now it is time to build the first pillar — a real repository. Initialization is a step you only do once, but mistakes here (especially around the password) become long-term disasters.
Keep this principle in mind: restic init creates the repository structure and an encryption key protected by a password. After this, the password is everything.
Before every restic command, get into the habit of exporting two variables so you do not have to repeat the flags:
export RESTIC_REPOSITORY=/backup/restic
export RESTIC_PASSWORD='h4sH-yang-sangat-Panjang-dan-Unik'RESTIC_REPOSITORY replaces -r, and RESTIC_PASSWORD avoids the interactive prompt — a must when used in cron or systemd (episode 9).
Initializing the local backend takes a single command:
restic init --repo /backup/resticcreated restic repository 2223e26e6b at /backup/restic
Please note that knowledge of your password is required to access
the repository. Losing your password means that your data is
irrecoverably lost.Without RESTIC_PASSWORD, restic will ask for the password twice. The note in the output is not empty words — losing the password means permanent data loss, and even restic itself has no backdoor.
For an S3-compatible backend (MinIO, AWS S3, GCS, Azure), the target is a bucket URL:
export AWS_ACCESS_KEY_ID=minioadmin
export AWS_SECRET_ACCESS_KEY=minioadmin
restic init -r s3:https://minio.example.com/backup-bucketThe bucket must already exist; restic does not create it automatically. For public S3 such as AWS, use the regional endpoint:
restic init -r s3:s3.ap-southeast-1.amazonaws.com/backup-bucketThe differences between backends and their configuration examples are covered in full in episode 7.
Instead of writing the URL in every command or env, store it in a file (for example /etc/restic/repo):
restic --repository-file /etc/restic/repo initThe file content is just one line: the repository URL. This makes centralized configuration and sharing the repository across scripts easier.
The repository password is the key to all your data. Here are some storage patterns, from the simplest to enterprise-grade:
export RESTIC_PASSWORD="$(cat /etc/restic/passphrase)"gpg -c /etc/restic/passphrase
export RESTIC_PASSWORD_FILE=/etc/restic/passphrase.gpgRESTIC_PASSWORD_FILE makes restic decrypt the file containing the password with gpg on every use.
For production, store it in Vault/OpenBao, AWS Secrets Manager, or a password manager, then inject it as an environment variable when the backup process runs.
Warning
Never write the repository password into a script that is committed to git or into a publicly readable config file. If the password leaks, your data remains safe from reading — but an attacker who can write to the repository could poison the snapshot history. If that happens, immediately change the password with restic key passwd (episode 13).
repository master key and config already initialized or a similar error. Always use a dedicated empty directory/bucket for the repository.RESTIC_PASSWORD is set — usually because the variable was not exported or the name is misspelled.repository master key and config already initialized only on a retry; the initial error is usually AccessDenied or NoSuchBucket — create the bucket first.restic init creates the repository + a password-protected encryption key.RESTIC_REPOSITORY and RESTIC_PASSWORD to avoid repeated prompts.restic -r s3:... init, make sure the bucket is created first.--repository-file separates the repo configuration from the command.In the next episode, episode 4, we run the first backup & snapshot — backing up a directory with tags and excludes, then inspecting the results with restic snapshots, restic stats, and restic ls. Your repository will come to life.