|
3 | 3 | This file regroups some useful combinations of different commands to efficiently manage your Scaleway resources.
|
4 | 4 | Do not hesitate to open a PR and share your favorite recipes.
|
5 | 5 |
|
| 6 | +## General |
| 7 | + |
| 8 | +### Retrieve specific field |
| 9 | + |
| 10 | +```bash |
| 11 | +## Retrieve all available instance type names |
| 12 | + |
| 13 | +# Using jq |
| 14 | +scw -o json instance server-type list | jq -r '.[].name' |
| 15 | +# Using CLI templates |
| 16 | +scw instance server-type list -o template="{{ .Name }}" |
| 17 | +``` |
| 18 | + |
| 19 | +### Filter output using jq |
| 20 | + |
| 21 | +```bash |
| 22 | +# Retrieve all available instance type with GPUs |
| 23 | +scw -o json instance server-type list | jq '.[] | select (.gpu > 0)'``` |
| 24 | +``` |
| 25 | + |
| 26 | +### Parallelize actions using xargs |
| 27 | + |
| 28 | +```bash |
| 29 | +## Reboot all listed servers at the same time, 8 max concurrent actions |
| 30 | +
|
| 31 | +# Using jq |
| 32 | +scw -o json instance server list | jq -r '.[].id' | xargs -L1 -P8 scw instance server reboot |
| 33 | +# Using CLI templates |
| 34 | +scw instance server list -o template="{{ .ID }}" | xargs -L1 -P8 scw instance server reboot |
| 35 | +``` |
| 36 | + |
| 37 | +### Create arguments for a cli command and use it in xargs |
| 38 | + |
| 39 | +```bash |
| 40 | +## List private-nics of all listed servers |
| 41 | +
|
| 42 | +# Using jq |
| 43 | +scw -o json instance server list | jq -r '.[] | "server-id=\(.id)"' | xargs -L1 scw instance private-nic list |
| 44 | +# Using CLI templates |
| 45 | +scw instance server list -o template="server-id={{ .ID }}" | xargs -L1 scw instance private-nic list |
| 46 | +``` |
| 47 | + |
6 | 48 | ## Instance
|
7 | 49 |
|
8 | 50 | ### Start/Stop a group of servers based on a tag
|
9 | 51 | ```bash
|
10 | 52 | # Start all servers with tag staging
|
11 |
| -scw -o json instance server list tags.0=staging | jq -r .[].id | xargs scw instance server start -w |
| 53 | +scw -o json instance server list tags.0=staging | jq -r '.[].id' | xargs scw instance server start -w |
12 | 54 |
|
13 | 55 | # Stop all servers with tag staging
|
14 |
| -scw -o json instance server list tags.0=staging | jq -r .[].id | xargs scw instance server stop -w |
| 56 | +scw -o json instance server list tags.0=staging | jq -r '.[].id' | xargs scw instance server stop -w |
| 57 | +``` |
| 58 | + |
| 59 | +### Servers and private networks |
| 60 | + |
| 61 | +```bash |
| 62 | +# Add all listed servers to a given private network |
| 63 | +scw -o json instance server list tags.0=staging | jq '.[].id' | xargs -t -I{} scw instance private-nic create private-network-id=<pn-id> server-id={} |
| 64 | +
|
| 65 | +# List all servers in a specific private network |
| 66 | +scw instance server list -ojson | jq 'map(select (.private_nics | map(select (.private_network_id == "<pn-id>")) | length == 1))' |
| 67 | +# List all servers not in a specific private network |
| 68 | +scw instance server list -ojson | jq 'map(select (.private_nics | map(select (.private_network_id == "<pn-id>")) | length == 0))' |
| 69 | +``` |
| 70 | + |
| 71 | +### Action on servers across multiple zones |
| 72 | + |
| 73 | +```bash |
| 74 | +## Reboot all servers across all zones, 8 server at a time |
| 75 | +
|
| 76 | +# Using jq |
| 77 | +scw -o json instance server list zone=all | jq -r '.[] | "\(.id) zone=\(.zone)"' | xargs -P8 -L1 scw instance server reboot |
| 78 | +# Using CLI templates |
| 79 | +scw instance server list zone=all -o template="{{.ID}} zone={{.Zone}}" | xargs -P8 -L1 scw instance server reboot |
| 80 | +``` |
| 81 | + |
| 82 | +## Database |
| 83 | + |
| 84 | +### Filter backups by date |
| 85 | + |
| 86 | +```bash |
| 87 | +# Get all backup older than 7 days |
| 88 | +scw rdb backup list -ojson | jq --arg d "$(date -d "7 days ago" --utc --iso-8601=ns)" '.[] | select (.created_at < $d)' |
15 | 89 | ```
|
0 commit comments