diff --git a/README.md b/README.md index 90e1fc5..dd5ffdd 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,7 @@ Options: access to [OPTIONAL]. -f gcloud filter expression to query disk selection [OPTIONAL] -p Prefix to be used for naming snapshots. + Max character length: 20 Default if not set: 'gcs' [OPTIONAL] -a Service Account to use. Blank if not set [OPTIONAL] @@ -130,13 +131,14 @@ By default snapshots are created with a prefix of `gcs`. To give a custom prefix Options: -p Prefix to be used for naming snapshots. + Max character length: 20 Default if not set: 'gcs' [OPTIONAL] For example: ./gcloud-snapshot.sh -p "my-snap" - (Note: Snapshot names are limited to 62 characters) + (Note: Snapshot prefixes are limited to 20 characters) ### Service Account By default snapshots are created with the default gcloud service account. To use a custom service account use the -a flag: diff --git a/gcloud-snapshot.sh b/gcloud-snapshot.sh index 5df42ba..2d0f9fb 100755 --- a/gcloud-snapshot.sh +++ b/gcloud-snapshot.sh @@ -28,6 +28,7 @@ usage() { echo -e " access to [OPTIONAL]." echo -e " -f gcloud filter expression to query disk selection [OPTIONAL]" echo -e " -p Prefix to be used for naming snapshots." + echo -e " Max character length: 20" echo -e " Default if not set: 'gcs' [OPTIONAL]" echo -e " -a Service Account to use." echo -e " Blank if not set [OPTIONAL]" @@ -92,7 +93,12 @@ setScriptOptions() # Snapshot Prefix if [[ -n $opt_p ]]; then - PREFIX=$opt_p + # check if prefix is more than 20 chars + if [ ${#opt_p} -ge 20 ]; then + PREFIX=${opt_p:0:20} + else + PREFIX=$opt_p + fi else PREFIX="gcs" fi