Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aws
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
709
public
restic
aws
Commits
72632c9e
Commit
72632c9e
authored
1 year ago
by
Ing. Michal Švamberg
Browse files
Options
Downloads
Patches
Plain Diff
Inicializacni verze skriptu
parent
eb5b25e7
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
bucket_copy.sh
+30
-0
30 additions, 0 deletions
bucket_copy.sh
delete_all.sh
+28
-0
28 additions, 0 deletions
delete_all.sh
with
58 additions
and
0 deletions
bucket_copy.sh
0 → 100644
+
30
−
0
View file @
72632c9e
#!/bin/bash
:
${
PROFILE
:
=
"cesnet_listvm_backup"
}
:
${
SRC_BUCKET
:
=
"resticlock"
}
:
${
DST_BUCKET
:
=
"restictmp"
}
:
${
DATE_THRESHOLD
:
=
"2024-02-26T10:20:30"
}
AWS_OPTS
=
"--endpoint-url https://s3.cl4.du.cesnet.cz --profile
${
PROFILE
}
"
# Vytvoření destination bucketu, pokud neexistuje
if
aws
$AWS_OPTS
s3
ls
"s3://
${
DST_BUCKET
}
"
2>&1 |
grep
-q
'NoSuchBucket'
then
aws
$AWS_OPTS
s3 mb s3://
${
DST_BUCKET
}
#aws $AWS_OPTS s3api put-bucket-versioning --bucket ${DST_BUCKET} --versioning-configuration Status=Enabled
fi
# Kopírování souborů včetně verzí
aws
$AWS_OPTS
s3api list-objects-v2
--bucket
$SRC_BUCKET
--query
'Contents[].Key'
--output
json | jq
-r
'.[]'
|
while
read
key
do
# Získej všechny verze tohoto objektu
versions
=
$(
aws
$AWS_OPTS
s3api list-object-versions
--bucket
$SRC_BUCKET
--prefix
"
$key
"
--output
json
)
# Filtruj verze podle data a vyber jen ty, které jsou mladší než datumový práh
version_id
=
$(
echo
"
$versions
"
| jq
-r
--arg
threshold
"
$DATE_THRESHOLD
"
'.Versions[] | select(.LastModified < $threshold) | .VersionId'
|
tail
-1
)
# Kopíruj vybranou verzi do cílového bucketu
if
[
-n
"
$version_id
"
]
;
then
aws
$AWS_OPTS
s3api copy-object
--bucket
$DST_BUCKET
--key
"
$key
"
--copy-source
"
$SRC_BUCKET
/
$key
?versionId=
$version_id
"
fi
done
This diff is collapsed.
Click to expand it.
delete_all.sh
0 → 100755
+
28
−
0
View file @
72632c9e
#!/bin/bash
:
${
BUCKET_NAME
:
=restictmp
}
:
${
PROFILE
:
=
"cesnet_listvm_backup"
}
CESNET
=
"--endpoint-url https://s3.cl4.du.cesnet.cz --profile
${
PROFILE
}
"
# Get list of all object versions
aws
${
CESNET
}
s3api list-object-versions
--bucket
"
${
BUCKET_NAME
}
"
--output
json | jq
-r
'.Versions[] | .Key + " " + .VersionId '
>
/tmp/versions.txt
# Delete all object versions
while
read
-r
LINE
;
do
KEY
=
$(
awk
'{print $1}'
<<<
"
$LINE
"
)
VERSION_ID
=
$(
awk
'{print $2}'
<<<
"
$LINE
"
)
aws
${
CESNET
}
s3api delete-object
--bucket
"
$BUCKET_NAME
"
--key
"
$KEY
"
--version-id
=
"
$VERSION_ID
"
done
< /tmp/versions.txt
# Get list of all delete markers
aws
${
CESNET
}
s3api list-object-versions
--bucket
"
$BUCKET_NAME
"
--output
json | jq
-r
'.DeleteMarkers[] | .Key + " " + .VersionId '
>
/tmp/delete_markers.txt
# Delete all delete markers
while
read
-r
LINE
;
do
KEY
=
$(
awk
'{print $1}'
<<<
"
$LINE
"
)
VERSION_ID
=
$(
awk
'{print $2}'
<<<
"
$LINE
"
)
aws
${
CESNET
}
s3api delete-object
--bucket
"
$BUCKET_NAME
"
--key
"
$KEY
"
--version-id
=
"
$VERSION_ID
"
done
< /tmp/delete_markers.txt
rm
/tmp/versions.txt
rm
/tmp/delete_markers.txt
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment