Complete Restructure and gitea
* Moved common functions + Started work on gitea
This commit is contained in:
parent
5c1a416b60
commit
b61e4066cb
|
@ -4,47 +4,17 @@
|
|||
# Determine the directory of the script
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
### [ Variables ] ###
|
||||
PROGRAM_NAME="Gitea Backup Script"
|
||||
|
||||
### [ Imports ] ###
|
||||
# Import Colors
|
||||
source "$SCRIPT_DIR/../lib/colors.sh"
|
||||
# Import configuration
|
||||
source "$SCRIPT_DIR/config.sh"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
NC='\033[0m' # No Color
|
||||
# Import Functions
|
||||
source "$SCRIPT_DIR/../lib/functions.sh"
|
||||
|
||||
### [ Functions ] ###
|
||||
check_required_programs() {
|
||||
local missing=0
|
||||
for program in gdrive 7zz sqlite3 curl; do
|
||||
if ! command -v $program &> /dev/null; then
|
||||
echo -e "${RED}Error: Required program '$program' is not installed.${NC}" >&2
|
||||
missing=1
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $missing -ne 0 ]; then
|
||||
local ERR_MSG="One or more required programs are missing."
|
||||
send_discord_notification "$ERR_MSG" "16711680"
|
||||
echo -e "${RED}$ERR_MSG${NC}" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
send_discord_notification() {
|
||||
local message=$1
|
||||
local color=$2
|
||||
|
||||
# Check if we should send discord notifications
|
||||
if [ -n "$DISCORD_WEB_HOOK" ]; then
|
||||
curl \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{ \"content\":\"\", \"embeds\":[{ \"title\":\"Vaultwarden Backup\", \"description\":\"${message}\", \"color\":${color}} ]}" \
|
||||
$DISCORD_WEB_HOOK
|
||||
fi
|
||||
}
|
||||
|
||||
get_7zip_password() {
|
||||
$SCRIPT_DIR/bitwarden_backup_password_decrypt.sh
|
||||
}
|
||||
|
@ -132,10 +102,10 @@ delete_old_gdrive_backups() {
|
|||
}
|
||||
|
||||
### [ Main ] ###
|
||||
echo -e "${YELLOW}Starting Vaultwarden backup...${NC}"
|
||||
echo -e "${YELLOW}Starting ${PROGRAM_NAME}...${NC}"
|
||||
send_discord_notification "Starting Vaultwarden backup..." "16776960" # Yellow color
|
||||
|
||||
check_required_programs
|
||||
check_required_programs "$SCRIPT_DIR/required_programs.txt"
|
||||
|
||||
backup_sqlite_database
|
||||
compress_and_encrypt_backup
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Here you can/should run a short script of getting your
|
||||
# password as plain text, I personally recommend
|
||||
# gpg key encryption of your key and decrypting it
|
||||
# at runtime, it really depends on what kind of setup you have
|
||||
|
||||
echo -e "example_password";
|
|
@ -0,0 +1,4 @@
|
|||
*gdrive
|
||||
7zz
|
||||
sqlite3
|
||||
*curl
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
# The name of the gitea container, this is required.
|
||||
GITEA_CONTAINER_NAME="gitea_app"
|
||||
# An absolute path to the gitea app.ini from within the docker container
|
||||
GITEA_CONF_PATH=/data/gitea/conf/app.ini
|
||||
# The path where WITHING THE CONTAINER the dump will be placed
|
||||
GITEA_BACKUP_CONTAINER_LOCATION=/backups
|
||||
|
||||
# The path that was mounted for gitea to push backups to
|
||||
BACKUP_SOURCE_PATH=/home/x/services/gitea/backups
|
||||
# Define the number of backups to keep (e.g., keep the latest 7 backups)
|
||||
KEEP_BACKUP_COUNT=3
|
||||
|
||||
# Discord Settings
|
||||
DISCORD_WEBHOOK=
|
||||
|
||||
# Google Drive Settings
|
||||
GOOGLE_DRIVE_FOLDER_ID=
|
|
@ -0,0 +1,56 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Preloader
|
||||
# Determine the directory of the script
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
PROGRAM_NAME="Gitea Backup Script"
|
||||
|
||||
### [ Imports ] ###
|
||||
# Import Colors
|
||||
source "$SCRIPT_DIR/../lib/colors.sh"
|
||||
# Import configuration
|
||||
source "$SCRIPT_DIR/config.sh"
|
||||
# Import Functions
|
||||
source "$SCRIPT_DIR/../lib/functions.sh"
|
||||
|
||||
### [ Functions ] ###
|
||||
|
||||
backup_from_docker() {
|
||||
# Reference to the gitea container id
|
||||
GITEA_DOCKER_CONTAINER=$(docker ps -qf name="${GITEA_CONTAINER_NAME}")
|
||||
|
||||
# Run the backup process
|
||||
if docker exec -w $GITEA_BACKUP_CONTAINER_LOCATION -u git $GITEA_DOCKER_CONTAINER bash -c "/usr/local/bin/gitea dump -c $GITEA_CONF_PATH"; then
|
||||
log "Gitea backup created successfully."
|
||||
else
|
||||
error "Failed to create Gitea backup."
|
||||
send_discord_notification "Failed to create Gitea backup."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine the path to the output file
|
||||
BACKUP_FILE=$(ls -Art $BACKUP_SOURCE_PATH/gitea-dump-*.zip | tail -n 1)
|
||||
|
||||
if [ -z "$BACKUP_FILE" ]; then
|
||||
error "Backup file not found."
|
||||
send_discord_notification "Backup file not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Backup file $BACKUP_FILE created."
|
||||
}
|
||||
|
||||
### [ Main ] ###
|
||||
echo -e "${YELLOW}Starting ${PROGRAM_NAME}...${NC}"
|
||||
send_discord_notification "Starting Vaultwarden backup..." "16776960" # Yellow color
|
||||
|
||||
check_required_programs "$SCRIPT_DIR/required_programs.txt"
|
||||
|
||||
backup_from_docker
|
||||
|
||||
# Run google drive backup
|
||||
|
||||
# Final message
|
||||
log "Backup process completed."
|
||||
send_discord_notification "Backup process completed."
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Here you can/should run a short script of getting your
|
||||
# password as plain text, I personally recommend
|
||||
# gpg key encryption of your key and decrypting it
|
||||
# at runtime, it really depends on what kind of setup you have
|
||||
|
||||
echo -e "example_password";
|
|
@ -0,0 +1,3 @@
|
|||
docker
|
||||
*gdrive
|
||||
*curl
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[0;33m'
|
||||
NC='\033[0m' # No Color
|
|
@ -0,0 +1,68 @@
|
|||
#!/bin/bash
|
||||
|
||||
send_discord_notification() {
|
||||
local message=$1
|
||||
local color=$2
|
||||
|
||||
# Check if we should send discord notifications
|
||||
if [ -n "$DISCORD_WEB_HOOK" ]; then
|
||||
curl \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{ \"content\":\"\", \"embeds\":[{ \"title\":\"Vaultwarden Backup\", \"description\":\"${message}\", \"color\":${color}} ]}" \
|
||||
$DISCORD_WEB_HOOK
|
||||
fi
|
||||
}
|
||||
|
||||
check_required_programs() {
|
||||
local requirements_file=$1
|
||||
local missing=0
|
||||
local optional_missing=0
|
||||
|
||||
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||
program=${line#\*}
|
||||
is_optional=false
|
||||
|
||||
if [[ "$line" == \** ]]; then
|
||||
is_optional=true
|
||||
fi
|
||||
|
||||
if ! command -v "$program" &> /dev/null; then
|
||||
if [ "$is_optional" = true ]; then
|
||||
echo -e "${YELLOW}Warning: Optional program '$program' is not installed.${NC}" >&2
|
||||
optional_missing=1
|
||||
else
|
||||
echo -e "${RED}Error: Required program '$program' is not installed.${NC}" >&2
|
||||
missing=1
|
||||
fi
|
||||
fi
|
||||
done < "$requirements_file"
|
||||
|
||||
if [ $missing -ne 0 ]; then
|
||||
local ERR_MSG="One or more required programs are missing."
|
||||
send_discord_notification "$ERR_MSG" "16711680"
|
||||
echo -e "${RED}$ERR_MSG${NC}" >&2
|
||||
exit 1
|
||||
elif [ $optional_missing -ne 0 ]; then
|
||||
local WARN_MSG="One or more optional programs are missing."
|
||||
send_discord_notification "$WARN_MSG" "16776960" # Yellow color code
|
||||
echo -e "${YELLOW}$WARN_MSG${NC}" >&2
|
||||
fi
|
||||
}
|
||||
|
||||
# Logging
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}Success: $1${NC}"
|
||||
}
|
||||
|
||||
log() {
|
||||
echo -e "${NC}$1${NC}"
|
||||
}
|
||||
|
||||
warn() {
|
||||
echo -e "${YELLOW}WARN: $1${NC}"
|
||||
}
|
||||
|
||||
error() {
|
||||
echo -e "${RED}ERROR: $1${NC}" >&2
|
||||
}
|
Loading…
Reference in New Issue