Update 'Backing up stuff in Google Cloud Storage'

Guillem Borrell Nogueras 2022-08-05 08:42:04 +02:00
parent 41b01bdc23
commit a6d3d102a6

@ -7,4 +7,71 @@ Once you have a subscription, these are the steps:
5. Install the google cloud SDK
6. Authenticate the google cloud command with the service principal (`gcloud auth activate-service-account --key-file=[KEY_FILE]
`)
7. Use the gcloud command to copy the local file to the bucket (`gcloud alpha storage cp /var/backups/cluster.sql gs://lab-backup-gbn/`)
7. Use the gcloud command to copy the local file to the bucket (`gcloud alpha storage cp /var/backups/cluster.sql gs://lab-backup-gbn/`). You may do it for the users root and postgres, so that they can also back up files.
8. Create and activate the following units and timers in systemd
## Files
### database-daily-backup.service
```
[Unit]
Description=Daily PG Backup
Documentation=man:pg_dumpall(8)
ConditionACPower=true
After=postgresql.service network.target network-online.target systemd-networkd.service NetworkManager.service connman.service
[Service]
Type=oneshot
User=postgres
Group=postgres
ExecStart=/usr/bin/pg_dumpall -c -f /var/backups/cluster.sql
ExecStartPost=/usr/bin/gcloud alpha storage cp /var/backups/cluster.sql gs://lab-backup-gbn/
KillMode=process
TimeoutStopSec=900
```
### database-daily-backup.timer
```
[Unit]
Description=Daily PG Backup
After=database-daily-backup.timer
[Timer]
OnCalendar=*-*-* 02:00
RandomizedDelaySec=10m
Persistent=true
[Install]
WantedBy=timers.target
```
### lab-daily-backup.service
```
[Unit]
Description=Daily Lab backpu
Documentation=man:tar(8)
ConditionACPower=true
After=network.target network-online.target systemd-networkd.service NetworkManager.service connman.service
[Service]
Type=oneshot
ExecStart=tar --exclude '/home/guillem/lab/storage' -zcpvf /var/backups/lab.tgz /home/guillem/lab
ExecStartPost=/usr/bin/gcloud alpha storage cp /var/backups/lab.tgz gs://lab-backup-gbn/
KillMode=process
TimeoutStopSec=900
```
### lab-daily-backup.timer
```
[Unit]
Description=Daily Lab Backup
After=lab-daily-backup.timer
[Timer]
OnCalendar=*-*-* 02:00
RandomizedDelaySec=10m
Persistent=true
[Install]
WantedBy=timers.target
```