LibrePortal/scripts/crontab/app/crontab_backup_all_apps.sh
librelad 875a60f90f LibrePortal v0.1.0 — initial release
A free, open, self-hosted app platform (GNU AGPLv3): one-click app deploys,
Traefik reverse proxy with automatic SSL, rootless Docker support, gluetun
VPN routing, and a web dashboard to manage it all.

Free & open forever to self-host; optional paid hosted services fund it.
See PROMISE.md.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-21 20:37:54 +01:00

55 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
crontabSetupAllAppBackups()
{
local show_header=$1
local ISCRON=$( (sudo -u $sudo_user_name crontab -l) 2>/dev/null )
# Check to see if installed
if [[ "$ISCRON" == *"command not found"* ]]; then
isNotice "Crontab is not found. Unable to set up backups."
fi
# Check to see if crontab is not installed
if ! sudo -u $sudo_user_name crontab -l 2>/dev/null | grep -q "cron is set up for $sudo_user_name" > /dev/null 2>&1; then
isNotice "Crontab is not set up, skipping until it's found."
fi
# Check if the database file exists
if [ ! -f "$docker_dir/$db_file" ]; then
isNotice "Database file not found: $docker_dir/$db_file"
fi
if [[ $show_header != "false" ]]; then
isHeader "Backup Crontab Install"
fi
local app_names=()
while IFS= read -r name; do
local app_names+=("$name")
done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 1;")
# Check if sqlite3 is available
if ! command -v sudo sqlite3 &> /dev/null; then
isNotice "sqlite3 command not found. Make sure it's installed."
fi
# Remove crontab entries for applications with status = 0 (uninstalled)
while IFS= read -r name; do
local uninstalled_apps+=("$name")
done < <(sudo sqlite3 "$docker_dir/$db_file" "SELECT name FROM apps WHERE status = 0;")
for name in "${uninstalled_apps[@]}"; do
removeBackupCrontabAppFolderRemoved $name
done
# Setup crontab entries for installed applications
for name in "${app_names[@]}"; do
checkBackupCrontabApp $name
done
crontabClean;
isSuccessful "Setting up Crontab backups for application(s) completed."
}