47 lines
1.4 KiB
Bash
47 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Simple Restic Installation Script
|
|
# Following Cloud Scripting best practices
|
|
|
|
set -e
|
|
|
|
echo "[INSTALL] Starting Restic installation..."
|
|
|
|
# Download and install Restic
|
|
echo "[INSTALL] Downloading Restic..."
|
|
curl -L https://github.com/restic/restic/releases/download/v0.15.2/restic_0.15.2_linux_amd64.bz2 -o restic.bz2
|
|
bzip2 -d restic.bz2
|
|
chmod +x restic
|
|
mv restic /usr/local/bin/
|
|
echo "[INSTALL] Restic installed successfully"
|
|
|
|
# Create password file
|
|
echo "[INSTALL] Setting up password file..."
|
|
if [ ! -f /etc/restic-password ]; then
|
|
head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16 > /etc/restic-password
|
|
echo "[INSTALL] Password file created"
|
|
fi
|
|
chmod 644 /etc/restic-password
|
|
|
|
# Create directories
|
|
echo "[INSTALL] Creating directories..."
|
|
mkdir -p /mnt/backups
|
|
mkdir -p /home/litespeed/mb-backups/logs
|
|
chmod -R 755 /home/litespeed/mb-backups/logs
|
|
chmod 755 /mnt/backups
|
|
|
|
# Initialize repository
|
|
echo "[INSTALL] Initializing repository..."
|
|
export RESTIC_PASSWORD=$(cat /etc/restic-password)
|
|
export RESTIC_REPOSITORY=/mnt/backups
|
|
|
|
if restic snapshots >/dev/null 2>&1; then
|
|
echo "[INSTALL] Repository already exists and is accessible"
|
|
else
|
|
echo "[INSTALL] Initializing new repository..."
|
|
rm -rf /mnt/backups/* 2>/dev/null || true
|
|
restic init
|
|
echo "[INSTALL] Repository initialized successfully"
|
|
fi
|
|
|
|
echo "[INSTALL] Installation completed successfully!" |