-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: scripts: add a backup and restore script
- Loading branch information
Showing
7 changed files
with
209 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-FileCopyrightText: Andrew Hayzen <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
set -e | ||
|
||
# | ||
# backup <machine-name> <user@host> <backup-dest> | ||
# | ||
|
||
# Check that rsync exists | ||
if [ ! -x "$(command -v rsync)" ]; then | ||
echo "rsync command not found, cannot backup" | ||
exit 1 | ||
fi | ||
RSYNC_ARGS="-avhP" | ||
|
||
HEADLESS_SYSTEM=false | ||
USER_HOST=$2 | ||
|
||
# Check that the machine name is known | ||
case $1 in | ||
vps) | ||
HEADLESS_SYSTEM=true | ||
;; | ||
*) | ||
echo "Unknown machine name" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Check that the target folder exists | ||
USER_DEST=$3 | ||
if [ ! -d "$USER_DEST" ]; then | ||
echo "Failed to find backup target" | ||
exit 1 | ||
fi | ||
BACKUP_DEST="$USER_DEST" | ||
|
||
# This is a normal headless system | ||
if [ $HEADLESS_SYSTEM ]; then | ||
export DOCKER_COMPOSE_RUNNER_DEST="$BACKUP_DEST/docker-compose-runner" | ||
mkdir -p "$DOCKER_COMPOSE_RUNNER_DEST" | ||
|
||
# Backup all of the docker data | ||
# | ||
# TODO: can we have a userns mapped folder for rsync to read/write from? | ||
# and even then potentially a user? | ||
"$(command -v rsync)" $RSYNC_ARGS --rsync-path="sudo rsync" "$USER_HOST:/var/lib/docker-compose-runner/" "$DOCKER_COMPOSE_RUNNER_DEST" | ||
fi | ||
|
||
# Ensure the filesystem is synced | ||
sync | ||
|
||
echo "Backup complete!" | ||
date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# SPDX-FileCopyrightText: Andrew Hayzen <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
set -e | ||
|
||
# | ||
# restore <machine-name> <restore-source> | ||
# | ||
|
||
# Check that rsync exists | ||
if [ ! -x "$(command -v rsync)" ]; then | ||
echo "rsync command not found, cannot restore" | ||
exit 1 | ||
fi | ||
RSYNC_ARGS="-avhP" | ||
|
||
HEADLESS_SYSTEM=false | ||
USER_HOST=$2 | ||
|
||
# Check that the machine name is known | ||
case $1 in | ||
vps) | ||
HEADLESS_SYSTEM=true | ||
;; | ||
*) | ||
echo "Unknown machine name" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Check that the source folder exists | ||
USER_SRC=$3 | ||
if [ ! -d "$USER_SRC" ]; then | ||
echo "Failed to find restore source" | ||
exit 1 | ||
fi | ||
RESTORE_SRC="$USER_SRC" | ||
|
||
# This is a normal headless system | ||
if [ $HEADLESS_SYSTEM ]; then | ||
export DOCKER_COMPOSE_RUNNER_SRC="$RESTORE_SRC/docker-compose-runner" | ||
if [ ! -d "$DOCKER_COMPOSE_RUNNER_SRC" ]; then | ||
echo "Failed to find docker-compose-runner data to restore" | ||
exit 1 | ||
fi | ||
|
||
# Stop services as we are about to mutate data | ||
ssh "$USER_HOST" sudo systemctl stop docker-compose-runner.service | ||
|
||
# Restore all of the docker data | ||
"$(command -v rsync)" $RSYNC_ARGS "$DOCKER_COMPOSE_RUNNER_SRC" "$USER_HOST:/var/lib/docker-compose-runner/" | ||
|
||
# Restart services | ||
ssh $USER_HOST sudo systemctl start docker-compose-runner.service | ||
fi | ||
|
||
echo "Restore complete!" | ||
date |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Host vps | ||
IdentityFile /etc/ssh/test_ssh_id_ed25519 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-----BEGIN OPENSSH PRIVATE KEY----- | ||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW | ||
QyNTUxOQAAACBwClEXAWm/c9/42a0VdvVowOxAkdiJUFyeqUwkNP5ioQAAAIj3ZErF92RK | ||
xQAAAAtzc2gtZWQyNTUxOQAAACBwClEXAWm/c9/42a0VdvVowOxAkdiJUFyeqUwkNP5ioQ | ||
AAAEAwbllncNKWZCOFyHkejkA4GZNBl9O6IKQf3pKpMj22SHAKURcBab9z3/jZrRV29WjA | ||
7ECR2IlQXJ6pTCQ0/mKhAAAABHRlc3QB | ||
-----END OPENSSH PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHAKURcBab9z3/jZrRV29WjA7ECR2IlQXJ6pTCQ0/mKh test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters