Update 2 files
- /install.sh - /undelete.py
This commit is contained in:
6
install.sh
Normal file
6
install.sh
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# for ubuntu
|
||||||
|
|
||||||
|
sudo apt install -y python3 python3-pip build-essential python-is-python3
|
||||||
|
|
||||||
|
pip install esdk-obs-python --trusted-host pypi.org
|
||||||
71
undelete.py
Normal file
71
undelete.py
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
import os
|
||||||
|
import traceback
|
||||||
|
from obs import ObsClient, Versions
|
||||||
|
|
||||||
|
bucket = input(f"""Insert bucket name: """)
|
||||||
|
prefiks = input(f"""Insert prefix for bucket: """)
|
||||||
|
|
||||||
|
ak = os.getenv(
|
||||||
|
"AKID"
|
||||||
|
)
|
||||||
|
|
||||||
|
sk = os.getenv(
|
||||||
|
"SKID"
|
||||||
|
)
|
||||||
|
|
||||||
|
endpoint = os.getenv(
|
||||||
|
"OBSENDPOINT"
|
||||||
|
)
|
||||||
|
|
||||||
|
obsClient = ObsClient(
|
||||||
|
access_key_id = ak,
|
||||||
|
secret_access_key = sk,
|
||||||
|
server = endpoint
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
undeleteVersions = []
|
||||||
|
|
||||||
|
mark = None
|
||||||
|
index = 1
|
||||||
|
|
||||||
|
while True:
|
||||||
|
|
||||||
|
listing = obsClient.listVersions(
|
||||||
|
bucket,
|
||||||
|
version = Versions(
|
||||||
|
prefix = prefiks,
|
||||||
|
encoding_type = 'url',
|
||||||
|
key_marker = mark,
|
||||||
|
max_keys = 1000
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if listing['status'] < 300:
|
||||||
|
for file_marker in listing['body']['markers']:
|
||||||
|
file_key = file_marker['key']
|
||||||
|
file_version = file_marker['versionId']
|
||||||
|
|
||||||
|
if file_marker['isLatest'] != True:
|
||||||
|
print(file_marker)
|
||||||
|
else:
|
||||||
|
undeleteObject = obsClient.deleteObject(
|
||||||
|
bucketName = bucket,
|
||||||
|
objectKey = file_key,
|
||||||
|
versionId = file_version
|
||||||
|
)
|
||||||
|
|
||||||
|
if undeleteObject['status'] > 204:
|
||||||
|
print(undeleteObject)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if listing['body']['head']['isTruncated'] == True:
|
||||||
|
mark = listing['body']['head']['nextKeyMarker']
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
except:
|
||||||
|
print('exception')
|
||||||
|
print(traceback.format_exc())
|
||||||
Reference in New Issue
Block a user