Skip to content

Commit e54e5d5

Browse files
authored
Snapshot name bug #59 (#70)
Restrict custom prefix to 20 characters
1 parent 1b383bc commit e54e5d5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Diff for: README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ Options:
6868
access to [OPTIONAL].
6969
-f gcloud filter expression to query disk selection [OPTIONAL]
7070
-p Prefix to be used for naming snapshots.
71+
Max character length: 20
7172
Default if not set: 'gcs' [OPTIONAL]
7273
-a Service Account to use.
7374
Blank if not set [OPTIONAL]
@@ -130,13 +131,14 @@ By default snapshots are created with a prefix of `gcs`. To give a custom prefix
130131
Options:
131132

132133
-p Prefix to be used for naming snapshots.
134+
Max character length: 20
133135
Default if not set: 'gcs' [OPTIONAL]
134136

135137
For example:
136138

137139
./gcloud-snapshot.sh -p "my-snap"
138140

139-
(Note: Snapshot names are limited to 62 characters)
141+
(Note: Snapshot prefixes are limited to 20 characters)
140142

141143
### Service Account
142144
By default snapshots are created with the default gcloud service account. To use a custom service account use the -a flag:

Diff for: gcloud-snapshot.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ usage() {
2828
echo -e " access to [OPTIONAL]."
2929
echo -e " -f gcloud filter expression to query disk selection [OPTIONAL]"
3030
echo -e " -p Prefix to be used for naming snapshots."
31+
echo -e " Max character length: 20"
3132
echo -e " Default if not set: 'gcs' [OPTIONAL]"
3233
echo -e " -a Service Account to use."
3334
echo -e " Blank if not set [OPTIONAL]"
@@ -92,7 +93,12 @@ setScriptOptions()
9293

9394
# Snapshot Prefix
9495
if [[ -n $opt_p ]]; then
95-
PREFIX=$opt_p
96+
# check if prefix is more than 20 chars
97+
if [ ${#opt_p} -ge 20 ]; then
98+
PREFIX=${opt_p:0:20}
99+
else
100+
PREFIX=$opt_p
101+
fi
96102
else
97103
PREFIX="gcs"
98104
fi

0 commit comments

Comments
 (0)