When you delete an object in a versioning-enabled bucket, OSS inserts a delete marker as the current version and retains all previous versions. Deleting the delete marker restores the latest previous version as the current version, making the object accessible again.
Delete all delete markers
Follow these steps to remove all delete markers from a bucket.
Step 1: Restore all objects
# Restore all objects hidden by delete markers in the bucket
ossutil revert oss://dest-bucket/ HEAD~0 -r -fParameters:
HEAD~0: Restores the object to its most recent valid version. If the current version is a delete marker, this command deletes the marker to restore the object.-r: Recursively processes all objects in the bucket.-f: Forces the operation and skips the confirmation prompt.
Sample output:
Success: Total 100 objects, Revert done:(100 objects)
0. xxx(s) elapsedStep 2: Verify the deletion
# Confirm that all delete markers have been deleted.
ossutil ls oss://dest-bucket/ --all-versions -r | grep "true.*true" | wc -l
# The expected output is 0.
# Check the number of restored objects.
ossutil ls oss://dest-bucket/ -r | grep "Object Number"Delete selected delete markers
Use this method to precisely remove specific delete markers from a bucket. This is useful when the delete markers originate from various sources, such as replication and manual deletion. This method requires ossutil version 2.2.1 or later.
Step 1: Create a list of objects
Create a file named deletemarker_list.txt and list the paths of the objects to restore, one per line:
data/report-2024-12.xlsx
images/product/banner.jpg
backup/database/
logs/2024/12/app.logFormatting rules:
Each line contains one object path relative to the bucket root.
Do not include the
oss://bucket-name/prefix.Directory objects must end with a forward slash (
/).
Step 2: Restore the objects
If your list file, deletemarker_list.txt, includes directory objects (paths ending in /), you must add the --support-dir-object parameter to the ossutil command.
1. Check for the specified objects
./ossutil ls oss://dest-bucket/ -r --files-from deletemarker_list.txt --support-dir-object2. Restore the deleted objects
./ossutil revert oss://dest-bucket/ HEAD~0 -f -r --files-from deletemarker_list.txt --support-dir-object3. Verify the restoration
Run the ls command again and compare the object count with the number of lines in your deletemarker_list.txt file:
./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.
Run in the background (optional)
To restore many objects without network interruptions, run the command as a background job:
# 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 executable
chmod +x revert.sh
# 3. Run in the background
nohup ./revert.sh &
# 4. Monitor progress (output is saved to nohup.out)
tail -f nohup.out