Git Product home page Git Product logo

automated-backup's Introduction

Automated Encrypted Backup Using Restic

Small script which automates my backups using restic and stores them encrypted on Infomaniak Swiss Backup.

Installation Ubuntu

To automate backups follow these simple steps:

  1. Save connection details in the secret-tool secret manager

    The connection details for the Infomaniak OpenStack Swift Keystone 3 backup location can be found in the Infomaniak Manager under Swiss Backup > Device management.

    First install secret-tool

    apt-get install libsecret-tools

    There are 4 secrets we want to add to the secret-tool keychain:

    # Infomaniak Swiss Backup username
    secret-tool store --label "restic" restic restic-os-username
    # Infomaniak Swiss Backup password
    secret-tool store --label "restic" restic restic-os-password
    # Restic password used to encrypt the backups
    secret-tool store --label "restic" restic restic-password
    # Healthcheck UUID
    secret-tool store --label "restic" restic restic-backup-healthcheck-uuid

    The restic-password keychain entry does not come from the OpenStack backup configuration. It is the encryption key used by restic to encrypt the backup before sending it to the remote location.

    The restic-backup-healthcheck-uuid keychain entry does come from healthchecks.io

  2. Configuration file

Create the file ```/home/user/.restic-config``` with this content:
```bash
export DISPLAY=:0 # see https://askubuntu.com/questions/1191300/how-to-use-secret-tool-in-cronjob-with-non-root-user
export OS_AUTH_URL=https://swiss-backup02.infomaniak.com/identity/v3
export OS_USER_DOMAIN_NAME=default
export OS_PASSWORD=$(secret-tool lookup restic restic-os-password)
export OS_USERNAME=$(secret-tool lookup restic restic-os-username)
export OS_PROJECT_DOMAIN_NAME=default
export OS_PROJECT_NAME="sb_project_$(secret-tool lookup restic restic-os-username)"
export RESTIC_PASSWORD=$(secret-tool lookup restic restic-password)
export RESTIC_REPOSITORY=swift:infomaniak:/
```
  1. Copy the backup script.

    Copy the file restic-backup.sh to ~/Scripts/ and execute

    chmod +x ~s/scripts/restic-backup-linux.sh
  2. Automate the backup using cron

Add the following line to your ```/etc/crontab```

```bash
*/10 * * * * user /home/user/scripts/restic-backup.sh >> /home/user/scripts/restic-backup-cron.log 2>&1
```

Installation MacOS

To automate backups follow these simple steps:

  1. Save connection details in the macOS keychain.

    The connection details for the Infomaniak OpenStack Swift Keystone 3 backup location can be found in the Infomaniak Manager under Swiss Backup > Device management.

    There are 4 secrets we want to add to the macOS keychain:

    security add-generic-password -s restic-backup-os-password -a restic-backup -w
    
    security add-generic-password -s restic-backup-os-username -a restic-backup -w
    
    security add-generic-password -s restic-backup-os-project-name -a restic-backup -w
    
    security add-generic-password -s restic-backup-repository-password -a restic-backup -w

    The last keychain entry does not come from the OpenStack backup configuration. It is the encryption key used by restic to encrypt the backup before sending it to the remote location.

  2. Configure restic.

    The configuration files for restic can be found in my dotfiles repository.

  3. Copy the backup script.

    Copy the file restic-backup.sh to ~/Scripts/ and execute

    chmod +x ~/Scripts/restic-backup.sh
  4. Automating the backup using launchd.

    Copy the file ch.yannishuber.restic-backup.plist to ~/Library/LaunchAgents/ and execute

    launchctl bootstrap gui/501 ~/Library/LaunchAgents/ch.yannishuber.restic-backup.plistq
  5. Give bash full disk access.

    In order for the script to execute properly, we have to give /bin/bash full disk access in the macOS system preferences: System Preferences > Security & Privacy > Full Disk Access.

That's it. The backups will be executed automatically every 8 hours.

Credits

Szymon Krajewski, https://szymonkrajewski.pl/macos-backup-restic/ Nicolas Feyer, https://github.com/nicolasfeyer

automated-backup's People

Contributors

yannishuber avatar nicolasfeyer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.