Newer
Older
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
set -eu
usage() {
echo "$0: BACKUP_SOURCE REGISTRY_DOMAIN"
}
if [ "${1:-}" = -h ] || [ "${1:-}" = --help ]
then
usage
exit 0
fi
if [ "$#" -ne 2 ]
then
usage
exit 1
fi
command -v skopeo >/dev/null || { echo 'skopeo is missing.' >&2; exit 2; }
src="$1"
registry="$2"
# There's an assumption here that filenames don't have spaces (or other such
# characters) as the image format prohibits that and I don't want to deal with
# such issues right now.
images="$(find "$src" -maxdepth 1 -mindepth 1 -type d -printf '%f\n')"
if [ -z "$images" ]
then
echo 'No images found,' >&2
exit 3
fi
returncode=0
for image in $images
do
tags="$(find "$src/$image" -maxdepth 1 -mindepth 1 -type f -name '*.tar' -printf '%f\n' | sed 's/\.tar$//g')"
if [ -z "$tags" ]
then
echo "No tags found for image $image, skipping." >&2
continue
fi
for tag in $tags
do
echo "Restoring $image:$tag" >&2
if skopeo copy "docker-archive://$src/$image/$tag.tar" "docker://$registry/$image:$tag"
then
echo "Restore finished successfully." >&2
else
echo "Restore failed, continuing with other image." >&2
returncode=1
fi
done
done
if [ "$returncode" -gt 0 ]
then
echo 'Restoration failed for some images.'
fi
exit "$returncode"