Proxmox-Backup Restore: Difference between revisions
Tag: wikieditor |
syntax Tag: 2017 source edit |
||
Line 1: | Line 1: | ||
= Proxmox Backup and Restore = | = Proxmox Backup and Restore = | ||
This guide | This guide provides options for consistently backing up a server, instructions for restoring from backups, and best practices for testing backups prior to needing them. | ||
Back to [[Server_Guides]] | Back to [[Server_Guides]] | ||
== Assumptions == | |||
This guide focuses on | This guide focuses on Proxmox servers and assumes: | ||
* A directory is established on the server for backups. Example: `/datadrive/Backups/` | |||
* Services run within containers and VMs on the Proxmox server (host). | |||
* SSH keys have been established and copied into each VM and container. Refer to the [[SSH Keys]] guide for more on SSH key generation and usage. | |||
For specific service guides, see: | |||
* [[Authentik Backup]] | |||
== Backup == | == Backup == | ||
<pre> | <pre># /usr/local/bin/proxmox-backup.sh | ||
#/usr/local/bin/proxmox-backup.sh | |||
# Define variables | |||
BACKUP_DIR="/datadrive/Backups" | BACKUP_DIR="/datadrive/Backups" | ||
VZ_DIR="/var/lib/vz/dump" | VZ_DIR="/var/lib/vz/dump" | ||
Line 30: | Line 25: | ||
VZ_REMOTE="pcloud:Backups/Server-Backups/VZDUMPS" | VZ_REMOTE="pcloud:Backups/Server-Backups/VZDUMPS" | ||
LOCAL_BACKUP_DIR="/datadrive/Backups" | LOCAL_BACKUP_DIR="/datadrive/Backups" | ||
# Authentik variables | |||
AUTHENTIK_REMOTE_USER="root" | AUTHENTIK_REMOTE_USER="root" | ||
AUTHENTIK_REMOTE_HOST="192.168.4.134" | AUTHENTIK_REMOTE_HOST="192.168.4.134" | ||
Line 36: | Line 32: | ||
TIMESTAMP=$(date +"%Y%m%d%H%M%S") | TIMESTAMP=$(date +"%Y%m%d%H%M%S") | ||
# Ensure remote backup directory exists | |||
ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "mkdir -p $AUTHENTIK_REMOTE_BACKUP_DIR" | ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "mkdir -p $AUTHENTIK_REMOTE_BACKUP_DIR" | ||
# Backup PostgreSQL Database | |||
ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker exec -i authentik-postgresql-1 /usr/local/bin/pg_dump --username authentik authentik > $AUTHENTIK_REMOTE_BACKUP_DIR/postgres-back" | ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker exec -i authentik-postgresql-1 /usr/local/bin/pg_dump --username authentik authentik > $AUTHENTIK_REMOTE_BACKUP_DIR/postgres-back" | ||
# Save Redis Database | |||
ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker exec -i authentik-redis-1 redis-cli save" | ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker exec -i authentik-redis-1 redis-cli save" | ||
# Copy Redis Dump | |||
ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker cp authentik-redis-1:/data/dump.rdb $AUTHENTIK_REMOTE_BACKUP_DIR/redis-backup-$TIMESTAMP.rdb" | ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker cp authentik-redis-1:/data/dump.rdb $AUTHENTIK_REMOTE_BACKUP_DIR/redis-backup-$TIMESTAMP.rdb" | ||
# Create Tarball of Necessary Files | |||
ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "tar czvf $AUTHENTIK_REMOTE_BACKUP_DIR/authentik-backup-$TIMESTAMP.tar.gz -C /home/authentik/authentik authentik docker-compose.yml certs" | ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "tar czvf $AUTHENTIK_REMOTE_BACKUP_DIR/authentik-backup-$TIMESTAMP.tar.gz -C /home/authentik/authentik authentik docker-compose.yml certs" | ||
# | # Sync from Authentik server to Proxmox backup | ||
rsync -avz --progress $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST:$AUTHENTIK_REMOTE_BACKUP_DIR $LOCAL_BACKUP_DIR/authentik_backups | |||
echo "Remote backup completed successfully." | echo "Remote backup completed successfully." | ||
</pre> | |||
== Restore == | == Restore == | ||
Instructions for restoring from backup will depend on the specific service and the type of backup used. Refer to the [[Authentik Backup]] or other service-specific guides for restoration steps. | |||
[[Category:Self-hosting]] | [[Category:Self-hosting]] | ||
[[Category:Guides]] | [[Category:Guides]] | ||
[[Category:Proxmox]] | |||
[[Category:Backups]] |
Latest revision as of 17:56, 3 December 2024
Proxmox Backup and Restore
This guide provides options for consistently backing up a server, instructions for restoring from backups, and best practices for testing backups prior to needing them.
Back to Server_Guides
Assumptions
This guide focuses on Proxmox servers and assumes:
- A directory is established on the server for backups. Example: `/datadrive/Backups/`
- Services run within containers and VMs on the Proxmox server (host).
- SSH keys have been established and copied into each VM and container. Refer to the SSH Keys guide for more on SSH key generation and usage.
For specific service guides, see:
Backup
# /usr/local/bin/proxmox-backup.sh # Define variables BACKUP_DIR="/datadrive/Backups" VZ_DIR="/var/lib/vz/dump" BACKUP_REMOTE="pcloud:Backups/Server-Backups" VZ_REMOTE="pcloud:Backups/Server-Backups/VZDUMPS" LOCAL_BACKUP_DIR="/datadrive/Backups" # Authentik variables AUTHENTIK_REMOTE_USER="root" AUTHENTIK_REMOTE_HOST="192.168.4.134" AUTHENTIK_REMOTE_BACKUP_DIR="/home/authentik/authentik/authentik_backups" TIMESTAMP=$(date +"%Y%m%d%H%M%S") # Ensure remote backup directory exists ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "mkdir -p $AUTHENTIK_REMOTE_BACKUP_DIR" # Backup PostgreSQL Database ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker exec -i authentik-postgresql-1 /usr/local/bin/pg_dump --username authentik authentik > $AUTHENTIK_REMOTE_BACKUP_DIR/postgres-back" # Save Redis Database ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker exec -i authentik-redis-1 redis-cli save" # Copy Redis Dump ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "docker cp authentik-redis-1:/data/dump.rdb $AUTHENTIK_REMOTE_BACKUP_DIR/redis-backup-$TIMESTAMP.rdb" # Create Tarball of Necessary Files ssh $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST "tar czvf $AUTHENTIK_REMOTE_BACKUP_DIR/authentik-backup-$TIMESTAMP.tar.gz -C /home/authentik/authentik authentik docker-compose.yml certs" # Sync from Authentik server to Proxmox backup rsync -avz --progress $AUTHENTIK_REMOTE_USER@$AUTHENTIK_REMOTE_HOST:$AUTHENTIK_REMOTE_BACKUP_DIR $LOCAL_BACKUP_DIR/authentik_backups echo "Remote backup completed successfully."
Restore
Instructions for restoring from backup will depend on the specific service and the type of backup used. Refer to the Authentik Backup or other service-specific guides for restoration steps.