Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit cfb21f1

Browse files
author
Nils K
committed
snapshots for windows
1 parent 82d2f4c commit cfb21f1

4 files changed

+157
-0
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
# Create snapshot of Compute Engine persistent boot disk
4+
5+
################################################################################
6+
# INCLUDE FUNCTIONS
7+
################################################################################
8+
9+
MY_INCLUDE='../inc/include.sh'
10+
# ignore SC1090
11+
# shellcheck source=/dev/null
12+
if ! source "$MY_INCLUDE"; then
13+
ME=$(basename "$0")
14+
BASE_PATH=$(dirname "$0")
15+
echo;echo "× Can not read required include file '$MY_INCLUDE'";echo
16+
echo " Please start the script directly in the directory:"
17+
echo " cd $BASE_PATH && bash $ME";echo
18+
exit 9
19+
fi
20+
21+
################################################################################
22+
# MAIN
23+
################################################################################
24+
25+
# Create snapshot of Compute Engine persistent boot disk
26+
# In:
27+
# MY_GCP_GCE_DISK_BOOT_NAME
28+
# MY_GCP_REGION
29+
# MY_GCP_ZONE
30+
# MY_GCP_PROJECT
31+
create_snapshot
32+
33+
# Check MY_WARNING and exit with echo_success or echo_failure
34+
# In: MY_WARNING
35+
check_warning_and_exit "Compute Engine disk snapshot created successfully"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
3+
# Create Compute Engine persistent boot disk from last snapshot and
4+
# create virtual machine instance with created disk
5+
6+
################################################################################
7+
# INCLUDE FUNCTIONS
8+
################################################################################
9+
10+
MY_INCLUDE='../inc/include.sh'
11+
# ignore SC1090
12+
# shellcheck source=/dev/null
13+
if ! source "$MY_INCLUDE"; then
14+
ME=$(basename "$0")
15+
BASE_PATH=$(dirname "$0")
16+
echo;echo "× Can not read required include file '$MY_INCLUDE'";echo
17+
echo " Please start the script directly in the directory:"
18+
echo " cd $BASE_PATH && bash $ME";echo
19+
exit 9
20+
fi
21+
22+
################################################################################
23+
# MAIN
24+
################################################################################
25+
26+
# Get last Compute Engine boot disk snapshot from specific instance
27+
# In: MY_GCP_GCE_NAME
28+
# Out: MY_GCE_SNAPSHOT_NAME
29+
get_last_snapshot_vm
30+
31+
# Use snapshot to create a new boot disk
32+
# In: MY_GCE_SNAPSHOT_NAME, MY_GCP_GCE_DISK_BOOT_NAME, MY_GCP_GCE_DISK_BOOT_TYPE
33+
create_disk_from_snapshot
34+
35+
# Create service account for virtual machine
36+
# In: MY_GCP_SA_NAME, MY_GCP_SA_DISPLAY_NAME, MY_GCP_SA_DESCRIPTION
37+
create_service_account
38+
# Get service account identifier or exit_with_failure
39+
# In: MY_GCP_SA_NAME
40+
# Out: MY_GCP_SA_ID
41+
get_service_account_identifier
42+
43+
# Add IAM roles (policy binding) to service account
44+
# In: MY_GCP_SA_ID, MY_GCP_SA_ROLES
45+
add_projects_policy_binding
46+
47+
# Add service account read access to storage bucket
48+
# In: MY_GCP_SA_ID, MY_GCP_STORAGE
49+
add_read_access_storage
50+
51+
# Create GCE virtual machine instance with already created disk
52+
# In:
53+
# MY_GCP_GCE_NAME
54+
# MY_GCP_ZONE
55+
# MY_GCP_GCE_TYPE
56+
# MY_GCP_SUBNET
57+
# MY_GCP_SA_ID
58+
# MY_GCP_GCE_DISK_BOOT_NAME
59+
create_disk_vm
60+
61+
# Check MY_WARNING and exit with echo_success or echo_failure
62+
# In: MY_WARNING
63+
check_warning_and_exit "Compute Engine virtual machine instance set up successfully"
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
# Delete all Compute Engine boot disk snapshots from specific instance
4+
5+
################################################################################
6+
# INCLUDE FUNCTIONS
7+
################################################################################
8+
9+
MY_INCLUDE='../inc/include.sh'
10+
# ignore SC1090
11+
# shellcheck source=/dev/null
12+
if ! source "$MY_INCLUDE"; then
13+
ME=$(basename "$0")
14+
BASE_PATH=$(dirname "$0")
15+
echo;echo "× Can not read required include file '$MY_INCLUDE'";echo
16+
echo " Please start the script directly in the directory:"
17+
echo " cd $BASE_PATH && bash $ME";echo
18+
exit 9
19+
fi
20+
21+
################################################################################
22+
# MAIN
23+
################################################################################
24+
25+
# Get last Compute Engine boot disk snapshot from specific instance
26+
# In: MY_GCP_GCE_NAME
27+
delete_all_snapshots_vm
28+
29+
# Check MY_WARNING and exit with echo_success or echo_failure
30+
# In: MY_WARNING
31+
check_warning_and_exit "All snapshots successfully deleted"

05_windows/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ Information without guarantee.
4949
* `99_delete_windows.sh` : Delete Compute Engine virtual machine instance and service account
5050
* `ZZ_debug.sh` : For debugging only
5151

52+
### Snapshots
53+
54+
If you don't need your VM for a long time you can make a snapshot from the disk.
55+
You can then delete the VM and the disk (`99_delete_windows.sh`).
56+
If you need the VM with the data again, you can create a new fresh VM from the snapshot.
57+
58+
* `30_create_snapshot_windows.sh` : Create snapshot of Compute Engine persistent boot disk
59+
* `31_create_from_snapshot_windows.sh` : Create Compute Engine persistent boot disk from last snapshot and create virtual machine instance with created disk
60+
* `39_delete_snapshots_windows.sh` : Delete all Compute Engine boot disk snapshots from specific instance
61+
62+
You will then save the [disk cost](https://cloud.google.com/compute/all-pricing#disk) and pay only the very cheap [snapshot price](https://cloud.google.com/compute/all-pricing#disk).
63+
64+
* Regional snapshot storage $0.029 per GB in `europe-north1` (Finland)
65+
* Multi-regional snapshot storage $0.0286 per GB in `eu` (European Union) [DEFAULT]
66+
67+
Example:
68+
69+
```shell
70+
# Create snapshot
71+
bash 30_create_snapshot_windows.sh
72+
# Delete SA, Disk and VM
73+
bash 99_delete_windows.sh
74+
# Later, create new VM from snapshot
75+
bash 31_create_from_snapshot_windows.sh
76+
# Delete all snapshots
77+
bash 39_delete_snapshots_windows.sh
78+
```
79+
5280
## RDP
5381

5482
Connect to Windows Server via RDP.

0 commit comments

Comments
 (0)