Skip to content

Instantly share code, notes, and snippets.

@joeperpetua
Created November 16, 2023 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeperpetua/0bce1eab2b2cb9a940015bd6bd3d5128 to your computer and use it in GitHub Desktop.
Save joeperpetua/0bce1eab2b2cb9a940015bd6bd3d5128 to your computer and use it in GitHub Desktop.
#!/bin/sh
TASK_ID=11;
REQ_VERSIONS=10;
SUCC_VERSIONS=0;
# Use a temporary file to store the JSON output
tmpfile=$(mktemp)
synowebapi --exec api=SYNO.ActiveBackup.Task method=list load_verify_status=true load_versions=true filter='{"task_id": '$TASK_ID', "data_formats": [1,4]}' version=1 | jq .data.tasks[0].versions > "$tmpfile"
# Use a C-style for loop or seq command
for i in $(seq 0 $REQ_VERSIONS);
do
echo 'Current version ID: ' $(jq ".[$i].version_id" "$tmpfile");
# If already reached successfull version number, delete current version
if [ $SUCC_VERSIONS -eq 10 ]
then
echo "Delete version";
echo $(synowebapi --exec api=SYNO.ActiveBackup.Version method=delete task_id=$TASK_ID version_ids=[$(jq ".[$i].version_id" "$tmpfile")] version=1);
break;
fi
# Check version status
if [ $(jq ".[$i].status" "$tmpfile") -eq 3 ]
then
echo "Successful version";
((SUCC_VERSIONS++));
fi
done
# Clean up the temporary file
rm "$tmpfile"
@joeperpetua
Copy link
Author

To get TASK_ID, you can run following command:
synowebapi --exec api=SYNO.ActiveBackup.Task method=list version=1 | jq '.data.tasks[] | "ID: \(.task_id) / Name: \(.task_name)"'
Output:

"ID: 1 / Name: Task-1"
"ID: 4 / Name: vmware_demo"
"ID: 6 / Name: backup-Default"
"ID: 8 / Name: joel-Default"
"ID: 9 / Name: Mint-VM"
"ID: 10 / Name: Rsync-FS"
"ID: 11 / Name: joel-Default"
"ID: 12 / Name: Incremental"
"ID: 14 / Name: SES - SMB - Multi"
"ID: 15 / Name: SES - SMB - Multi - Enc"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment