Created
November 16, 2023 11:34
-
-
Save joeperpetua/0bce1eab2b2cb9a940015bd6bd3d5128 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: