Skip to content

Back up YouTrack database to Backblaze B2 bucket

License

Notifications You must be signed in to change notification settings

silinternational/youtrack-backup

Repository files navigation

youtrack-backup

Perl script to create a backup of the YouTrack Cloud database, store it in a Backblaze B2 bucket, and optionally delete old backup files.

Environment variables

  • YT_TOKEN - YouTrack permanent access token
  • B2_APPLICATION_KEY_ID - Backblaze application key ID
  • B2_APPLICATION_KEY - Backblaze application key secret

Arguments

  • --baseurl - YouTrack Cloud URL.
  • --bucket - Backblaze bucket name.
  • --delay - [optional] Seconds to wait between checks for database backup completion. (Default: 30)
  • --keep - [optional] Number of backup files to keep. (Default: 0, keep all backup files)
  • --quiet - [optional] Don't print information progress messages.
  • --help - [optional] Print usage message and exit.

How to use youtrack-backup.pl

  1. Obtain a YouTrack Cloud permanent access token.
    1. Log into YouTrack Cloud.
    2. Navigate to the Account Security tab in your Profile.
    3. Click New token... in the Tokens section.
    4. Provide a name for the token and ensure the Scope contains YouTrack and YouTrack Administration.
    5. Set and export the environment variable YT_TOKEN with the YouTrack Cloud access token as its value (e.g., use a command like export YT_TOKEN=youtrack-cloud-access-token). Note that preceding the export command with a space may prevent the command from being stored in the shell history. Refer to the description of the HISTCONTROL shell variable in the bash man page for details.
  2. Install b2.
  3. Create a Backblaze B2 bucket.
    1. Log into Backblaze.
    2. In the left navigation area, click Buckets.
    3. Click Create a Bucket.
      • Bucket Unique Name: supply a name
      • Files in Bucket are: Private
      • Default Encryption: Enable
      • Object Lock: Disable
    4. Click Create a Bucket.
  4. Obtain a Backblaze Application Key. This manual process will restrict access to the B2 bucket you just created. The application key will have these capabilities: deleteFiles, listBuckets, listFiles, readBucketEncryption, readBucketReplications, readBuckets, readFiles, shareFiles, writeBucketEncryption, writeBucketReplications, writeFiles.
    1. Log into Backblaze.
    2. In the left navigation area, click Application Keys.
    3. Click Add a New Application Key.
      • Name of Key: supply a name
      • Allow access to Bucket(s): select the bucket you just created
      • Type of Access: Read and Write
      • Allow List All Bucket Names: not selected
      • File name prefix: leave blank
      • Duration: leave blank
    4. Click Create New Key.
    5. Save the keyID, keyName, and applicationKey in a secure location.
  5. Set and export the environment variable B2_APPLICATION_KEY_ID with the Backblaze access token ID as its value.
  6. Set and export the environment variable B2_APPLICATION_KEY with the Backblaze access token secret as its value.
  7. To perform a YouTrack Cloud database backup: youtrack-backup.pl --baseurl yt-url --bucket b2-bucket-name

Example use with Docker and Backblaze

Additional environment variables

  • YT_URL - URL to your instance of YouTrack Cloud.
  • B2_BUCKET - Name of the Backblaze B2 bucket.
  • KEEP_COUNT - Number of backups to keep.

The image created by the Dockerfile will run youtrack-backup.pl with --delay defaulted to 30, --keep defaulted to 0, and --quiet disabled.

  1. Copy local.env.dist to local.env.
  2. Set the values for the variables contained in local.env.
  3. Build the Docker image: docker build --tag youtrack-backup:latest .
  4. Run the Docker image: docker run --env-file=local.env youtrack-backup:latest

Docker Hub

This image is built automatically on Docker Hub as silintl/youtrack-backup