Delete a delete marker
A delete marker is a special object in Object Storage Service (OSS) that indicates an object was deleted in a versioning-enabled bucket. When you delete an object in such a bucket, OSS adds a delete marker as the current version of the object and keeps all previous versions. If you delete the delete marker, the object becomes accessible again and the previous version is restored as the current version.
Delete all delete markers
To remove all delete markers from a bucket, follow these steps.
Step 1: Perform a full restoration
# Restore all objects hidden by delete markers in the entire bucket.
ossutil revert oss://dest-bucket/ HEAD~0 -r -fParameter description:
HEAD~0: Restores the object to its previous version. If the current version is a delete marker, this command deletes the marker to restore the previous version.-r: Recursively processes all objects in the bucket.-f: Forces the operation without a confirmation prompt.
Example output:
Success: Total 100 objects, Revert done:(100 objects)
0. xxx(s) elapsedStep 2: Verify the deletion
# Confirm that all delete markers are deleted.
ossutil ls oss://dest-bucket/ --all-versions -r | grep "true.*true" | wc -l
# The output should be 0.
# View the number of restored objects.
ossutil ls oss://dest-bucket/ -r | grep "Object Number"Selectively delete delete markers from a list
Use this method to selectively delete specific delete markers. This is useful when a bucket contains delete markers created for different reasons, such as cross-region replication and manual deletion. Make sure that you use ossutil 2.2.1 or later.
Step 1: Prepare a file that lists the delete markers
Create a file named deletemarker_list.txt and list one object path to restore per line:
data/report-2024-12.xlsx
images/product/banner.jpg
backup/database/
logs/2024/12/app.logList format description:
Each line contains one object path relative to the bucket's root directory.
Do not include the
oss://bucket-name/prefix.Directory objects must end with a forward slash (
/).
Step 2: Perform the restoration
If the list file deletemarker_list.txt contains directory objects (that end with /), you must add the --support-dir-object parameter to the ossutil command.
Step 1: Check which objects in the list already exist in OSS
./ossutil ls oss://dest-bucket/ -r --files-from deletemarker_list.txt --support-dir-objectStep 2: Restore the deleted objects
./ossutil revert oss://dest-bucket/ HEAD~0 -f -r --files-from deletemarker_list.txt --support-dir-objectStep 3: Verify the restoration
Run the command from Step 1 again. Compare the number of objects returned by the command with the number of records in deletemarker_list.txt:
./ossutil ls oss://dest-bucket/ -r --files-from deletemarker_list.txt --support-dir-object | grep "Object Number is:" | cut -d":" -f2
wc -l deletemarker_list.txtIf the two numbers match, all objects were successfully restored.
Optional: Run the command in the background to prevent network interruptions
If you have many objects, run the command in the background:
# 1. Create a script file.
cat > revert.sh << 'EOF'
#!/bin/bash
./ossutil revert oss://dest-bucket/ HEAD~0 -f -r --files-from deletemarker_list.txt --support-dir-object
EOF
# 2. Make the script an executable file.
chmod +x revert.sh
# 3. Run the command in the background.
nohup ./revert.sh &
# 4. Check the progress (the output is saved to the nohup.out file).
tail -f nohup.out