SPB Git

Repository Public License

08-folder-backup-and-verify.yaml 4.9 KB 132 lines yaml

1# ORIX OS Automation2# File: Workflows/Examples/08-folder-backup-and-verify.yaml3# Description: Built-in automation: archives a folder into a dated zip, restores it into a temporary folder and compares it with the source.4#5# Author: Simon-Pierre Boucher6# Contact: contact@spboucher.ai7#8# Limitations9# - This is a local copy, not an off-site backup: it protects against mistakes, not against losing the disk.10# - Verification restores the archive into a temporary folder under the backup root and compares it with the source11#   (hidden files included); it needs free space for archive + restored copy. The temporary folder is moved to the12#   Trash afterwards, not erased: empty the Trash to get the space back.13# - One archive per day: a second run on the same day replaces that day's archive (the replaced file is first copied14#   to the run's artifacts).15# - Files that change during the run can make the comparison fail; that is reported as a failed verification, not hidden.16# - Symbolic links are archived as links; a comparison of more than 500 differences is truncated in the output.17# - Old backups are never pruned.18# - Nothing runs while the Mac is off or asleep at 02:00; see the scheduler's missed-run policy.19# - The notification needs the ORIX app (a command-line run has no application bundle): there the last step fails by20#   itself and the run ends PARTIALLY_SUCCEEDED with the backup made and verified.21apiVersion: orix.ai/v122kind: Automation23metadata:24  id: folder-backup-and-verify25  name: Folder backup and verification26  description: >-27    Archives a folder into a dated zip, records its SHA-256, restores the archive into a temporary folder,28    compares the restored tree with the source and only then reports the backup as good.29  tags: [backup, archive, verify, schedule]30spec:31  triggers:32    - type: schedule33      cron: "0 2 * * *"34      timezone: America/Toronto35    - type: manual36  parameters:37    - name: source38      type: path39      default: ~/ORIX Samples/folder-backup-and-verify/Documents40      description: Folder to back up.41    - name: backupRoot42      type: path43      default: ~/ORIX Samples/folder-backup-and-verify/Backups44      description: Folder that receives the dated archives.45  permissions:46    filesystem:47      read: ["${{ params.source }}", "${{ params.backupRoot }}"]48      write: ["${{ params.backupRoot }}"]49      delete: ["${{ params.backupRoot }}"]50    notifications: true51  budget:52    maxDurationSeconds: 360053    maxToolCalls: 2054  steps:55    - id: paths56      set:57        archive: ${{ params.backupRoot }}/backup-${{ env.DATE }}.zip58        restored: ${{ params.backupRoot }}/.verify-${{ env.TIMESTAMP }}59    - id: prepare60      tool: filesystem.mkdir61      with:62        path: ${{ params.backupRoot }}63    - id: archive64      name: Create the archive65      needs: [paths, prepare]66      tool: filesystem.archive67      with:68        source: ${{ params.source }}69        destination: ${{ vars.archive }}70        keepParent: true71        overwrite: true72      timeoutSeconds: 180073    - id: checksum74      needs: [archive]75      tool: filesystem.checksum76      with:77        path: ${{ vars.archive }}78    - id: record79      name: Record the checksum80      needs: [checksum]81      tool: filesystem.write82      with:83        path: ${{ vars.archive }}.sha25684        content: "${{ steps.checksum.output.digest }}  ${{ basename(vars.archive) }}\n"85        overwrite: true86    - id: restore87      name: Restore into a temporary folder88      needs: [archive]89      tool: filesystem.unarchive90      with:91        source: ${{ vars.archive }}92        destination: ${{ vars.restored }}93      timeoutSeconds: 180094    - id: compare95      name: Compare the restored copy with the source96      needs: [restore]97      tool: filesystem.compare98      with:99        source: ${{ params.source }}100        destination: ${{ joinPath(vars.restored, basename(params.source)) }}101        includeHidden: true102    - id: cleanup103      name: Move the temporary copy to the Trash104      needs: [compare]105      tool: filesystem.trash106      with:107        path: ${{ vars.restored }}108    - id: check109      needs: [compare, record, cleanup]110      verify:111        - fileNonEmpty: ${{ vars.archive }}112        - fileContains: ${{ vars.archive }}.sha256113          text: ${{ steps.checksum.output.digest }}114        - equals: ["${{ steps.compare.output.kind }}", directories]115        - truthy: ${{ steps.compare.output.identical }}116    - id: result117      needs: [check]118      output:119        archive: ${{ vars.archive }}120        sha256: ${{ steps.checksum.output.digest }}121        bytes: ${{ steps.checksum.output.bytes }}122        entries: ${{ steps.restore.output.count }}123        identical: ${{ steps.compare.output.identical }}124      artifacts:125        - ${{ vars.archive }}126        - ${{ vars.archive }}.sha256127    - id: announce128      needs: [result]129      notify: Backup verified, SHA-256 ${{ slice(steps.checksum.output.digest, 0, 12) }}…130      title: Folder backup131      continueOnError: true132
Files main
Menu

Theme