-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbackup_caldera.sh
More file actions
33 lines (29 loc) · 1.24 KB
/
backup_caldera.sh
File metadata and controls
33 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root or with sudo"
exit 1
fi
# Check if caldera service exists
if ! systemctl list-unit-files | grep -q "caldera.service"; then
echo "Caldera service not found. Please create caldera.service, enable and start it before running this script."
exit 1
fi
USERNAME=${SUDO_USER:-$(whoami)}
BACKUP_DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/var/backups/caldera"
LOG_FILE="/var/log/caldera.log"
CALDERA_DIR="/opt/caldera"
mkdir -p ${BACKUP_DIR}
echo "Stopping caldera service."
sudo systemctl stop caldera.service
cd $(dirname ${CALDERA_DIR})
echo "Starting caldera backup."
tar -czf ${BACKUP_DIR}/caldera_backup_${BACKUP_DATE}.tar.gz $(basename ${CALDERA_DIR})
BACKUP_SIZE=$(du -h ${BACKUP_DIR}/caldera_backup_${BACKUP_DATE}.tar.gz | cut -f1)
echo "[$(date)] Caldera backup created: ${BACKUP_DIR}/caldera_backup_${BACKUP_DATE}.tar.gz Size: ${BACKUP_SIZE}" >> ${LOG_FILE}
# Keep only last 5 backups
cd ${BACKUP_DIR} && ls -t caldera_backup_*.tar.gz | tail -n +6 | xargs -r rm
echo "Caldera backup created: ${BACKUP_DIR}/caldera_backup_${BACKUP_DATE}.tar.gz. Size: ${BACKUP_SIZE}. Last 5 backups kept."
echo "Starting caldera service"
sudo systemctl start caldera.service