Skip to content

Instantly share code, notes, and snippets.

@MathiasReker
Last active October 27, 2024 16:31
Show Gist options
  • Select an option

  • Save MathiasReker/f1c8cadfe0d01add5e4613f1d43b3cb2 to your computer and use it in GitHub Desktop.

Select an option

Save MathiasReker/f1c8cadfe0d01add5e4613f1d43b3cb2 to your computer and use it in GitHub Desktop.

Revisions

  1. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -59,7 +59,6 @@ COMMIT_MESSAGE=":safety_vest: [$HA_VERSION]: $COMMIT_CURRENT_DATE"
    sudo git add /backup
    sudo git commit -m "$COMMIT_MESSAGE"
    sudo git push -u origin master -f
    sudo git lfs prune
    ```

    # Create a NodeRed flow that creates a full backup and run /backup.sh afterwards
  2. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -59,6 +59,7 @@ COMMIT_MESSAGE=":safety_vest: [$HA_VERSION]: $COMMIT_CURRENT_DATE"
    sudo git add /backup
    sudo git commit -m "$COMMIT_MESSAGE"
    sudo git push -u origin master -f
    sudo git lfs prune
    ```

    # Create a NodeRed flow that creates a full backup and run /backup.sh afterwards
  3. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Home Assistant Backup
    # Home Assistant Backup to GitHub

    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups from a NodeRed flow.

  4. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ This guide explain how to automates the process of backing up your Home Assistan
    - Configure the addon with a password. You need this password later on in the Node Red flow.

    ### 3. Initialize Git Repository
    SSH in to the server and run the following commands in your terminal:
    SSH into the server and run the following commands in your terminal:

    ```
    cd /
  5. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Home Assistant Backup

    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via NodeRed.
    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups from a NodeRed flow.

    > This guide is for advanced users. This guide is for Alpine Linux.
  6. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Home Assistant Backup

    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a NodeRed.
    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via NodeRed.

    > This guide is for advanced users. This guide is for Alpine Linux.
  7. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Home Assistant Backup

    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a script.
    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a NodeRed.

    > This guide is for advanced users. This guide is for Alpine Linux.
  8. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Home Assistant Backup

    This project automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a script.
    This guide explain how to automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a script.

    > This guide is for advanced users. This guide is for Alpine Linux.
  9. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ sudo echo "/*\n!/backup/\n!.gitattributes" >> .gitignore
    sudo git remote add origin https://REPLACE_WITH_USERNAME:[email protected]/REPLACE_WITH_USERNAME/homeassistant-backup.git
    ```

    #### Install Git LFS to uplodad files > 100 MB
    ### Install Git LFS to uplodad files > 100 MB
    ```
    sudo apk add git-lfs
    sudo git lfs install
    @@ -37,7 +37,7 @@ sudo git commit -m "Track .tar files with Git LFS"
    sudo git push -u origin master -f
    ```

    # Create the backup script:
    # Create the backup script
    ```
    cd /
    sudo nano backup.sh
    @@ -61,7 +61,7 @@ sudo git commit -m "$COMMIT_MESSAGE"
    sudo git push -u origin master -f
    ```

    # Create a NodeRed flow that creates a full backup and run /backup.sh afterwards:
    # Create a NodeRed flow that creates a full backup and run /backup.sh afterwards

    ```
    [{"id":"fd49290bbbf4cafa","type":"exec","z":"a6541044a83813f3","command":"sshpass -pREPLACE_THIS_WITH_PASSWORD ssh -o StrictHostKeyChecking=no [email protected] 'bash /backup.sh'","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":490,"y":300,"wires":[[],[],[]]}]
  10. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Home Assistant Backup

    This project automates the process of backing up your Home Assistant configuration to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a script.
    This project automates the process of backing up your Home Assistant backup files (`/backup` directory) to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a script.

    > This guide is for advanced users. This guide is for Alpine Linux.
  11. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,7 @@ sudo git push -u origin master -f
    ```

    # Create the backup script:
    bash```
    ```
    cd /
    sudo nano backup.sh
    ```
  12. MathiasReker revised this gist Oct 27, 2024. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions home_assistant_backup_github.md
    Original file line number Diff line number Diff line change
    @@ -19,15 +19,15 @@ This project automates the process of backing up your Home Assistant configurati
    ### 3. Initialize Git Repository
    SSH in to the server and run the following commands in your terminal:

    ```bash
    ```
    cd /
    sudo git init
    sudo echo "/*\n!/backup/\n!.gitattributes" >> .gitignore
    sudo git remote add origin https://REPLACE_WITH_USERNAME:[email protected]/REPLACE_WITH_USERNAME/homeassistant-backup.git
    ```

    #### Install Git LFS to uplodad files > 100 MB
    bash```
    ```
    sudo apk add git-lfs
    sudo git lfs install
    sudo git lfs track "*.tar"
    @@ -45,7 +45,7 @@ sudo nano backup.sh
    Add:
    bash```
    ```
    #!/usr/bin/env bash
    set -e
    HA_VERSION_FILE="/homeassistant/.HA_VERSION"
    @@ -63,6 +63,6 @@ sudo git push -u origin master -f
    # Create a NodeRed flow that creates a full backup and run /backup.sh afterwards:
    json```
    ```
    [{"id":"fd49290bbbf4cafa","type":"exec","z":"a6541044a83813f3","command":"sshpass -pREPLACE_THIS_WITH_PASSWORD ssh -o StrictHostKeyChecking=no [email protected] 'bash /backup.sh'","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":490,"y":300,"wires":[[],[],[]]}]
    ```
  13. MathiasReker renamed this gist Oct 27, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  14. MathiasReker created this gist Oct 27, 2024.
    68 changes: 68 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    # Home Assistant Backup

    This project automates the process of backing up your Home Assistant configuration to a private GitHub repository. It includes steps for setting up GitHub, configuring Git, and running backups via a script.

    > This guide is for advanced users. This guide is for Alpine Linux.

    ## Setup Instructions

    ### 1. GitHub Repository
    1. Go to [GitHub](https://github.com).
    2. Create a private repository named `homeassistant-backup`.
    3. Set the default branch to `master`.
    4. Generate a token with no expiration and full permissions for this specific repository.

    ### 2. Install Required Add-ons
    - Install the **Advanced SSH & Web Terminal** add-on in Home Assistant.
    - Configure the addon with a password. You need this password later on in the Node Red flow.

    ### 3. Initialize Git Repository
    SSH in to the server and run the following commands in your terminal:

    ```bash
    cd /
    sudo git init
    sudo echo "/*\n!/backup/\n!.gitattributes" >> .gitignore
    sudo git remote add origin https://REPLACE_WITH_USERNAME:[email protected]/REPLACE_WITH_USERNAME/homeassistant-backup.git
    ```

    #### Install Git LFS to uplodad files > 100 MB
    bash```
    sudo apk add git-lfs
    sudo git lfs install
    sudo git lfs track "*.tar"

    sudo git add .gitattributes .gitignore
    sudo git commit -m "Track .tar files with Git LFS"
    sudo git push -u origin master -f
    ```

    # Create the backup script:
    bash```
    cd /
    sudo nano backup.sh
    ```

    Add:

    bash```
    #!/usr/bin/env bash
    set -e
    HA_VERSION_FILE="/homeassistant/.HA_VERSION"
    if [[ ! -f $HA_VERSION_FILE ]]; then
    echo "Error: Home Assistant version file not found at $HA_VERSION_FILE"
    exit 1
    fi
    HA_VERSION=$(cat "$HA_VERSION_FILE")
    COMMIT_CURRENT_DATE=$(date +'%d-%m-%Y %H:%M:%S')
    COMMIT_MESSAGE=":safety_vest: [$HA_VERSION]: $COMMIT_CURRENT_DATE"
    sudo git add /backup
    sudo git commit -m "$COMMIT_MESSAGE"
    sudo git push -u origin master -f
    ```

    # Create a NodeRed flow that creates a full backup and run /backup.sh afterwards:

    json```
    [{"id":"fd49290bbbf4cafa","type":"exec","z":"a6541044a83813f3","command":"sshpass -pREPLACE_THIS_WITH_PASSWORD ssh -o StrictHostKeyChecking=no [email protected] 'bash /backup.sh'","addpay":"","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":490,"y":300,"wires":[[],[],[]]}]
    ```