<commit_before>#!/bin/bash
# LGSM command_backup.sh function
# Author: <NAME>
# Website: https://gameservermanagers.com
# Description: Creates a .tar.gz file in the backup directory.

local commandname="BACKUP"
local commandaction="Backup"
local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"

check.sh
# Check if a backup is pending or has been aborted using .backup.lock
if [ -f "${tmpdir}/.backup.lock" ]; then
	fn_print_warning_nl "A backup is currently pending or has been aborted."
	while true; do
		read -e -i "y" -p "Continue anyway? [Y/N]" yn
		case $yn in
		[Yy]* ) break;;
		[Nn]* ) echo Exiting; return;;
		* ) echo "Please answer yes or no.";;
	esac
	done
fi
info_distro.sh
fn_print_dots ""
sleep 0.5
# Prepare backup file name with servicename current date
backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')"
# Tells how much will be compressed using rootdirduexbackup value from info_distro
fn_print_info_nl "A total of ${rootdirduexbackup} will be compressed into the following backup:"
echo "${backupdir}/${backupname}.tar.gz"
while true; do
	read -e -i "y" -p "Continue? [Y/N]" yn
	case $yn in
	[Yy]* ) break;;
	[Nn]* ) echo Exiting; return;;
	* ) echo "Please answer yes or no.";;
esac
done
check_status.sh
if [ "${status}" != "0" ]; then
	echo ""
	fn_print_warning_nl "${servicename} is currently running."
	sleep 1
	while true; do
		read -p "Stop ${servicename} while running the backup? [Y/N]" yn
		case $yn in
		[Yy]* ) command_stop.sh; serverstopped="yes"; break;;
		[Nn]* ) serverstopped="no"; break;;
		* ) echo "Please answer yes or no.";;
	esac
	done
fi

fn_print_dots "Backup in progress, please wait..."
fn_script_log_info "Started backup"
sleep 1
if [ ! -d "${backupdir}" ]; then
	mkdir "${backupdir}"
fi
# Create lockfile
touch "${tmpdir}/.backup.lock"
# Compressing files
tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "backups" ./*
# Remove lockfile
rm "${tmpdir}/.backup.lock"
# Check tar exit code and act accordingly
if [ $? == 0 ]; then
	fn_print_ok_nl "Backup created: ${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
	fn_script_log_pass "Backup created: ${backupdir}/${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
	
	# Clear old backups if backupdays variable exists
	if [ -n "${backupdays}" ]; then
		# Count how many backups can be cleared
		backupclearcount=$(find "${backupdir}"/ -type f -mtime +"${backupdays}"|wc -l)
		# Check if there is any backup to clear
		if [ "${backupclearcount}" -ne "0" ]; then
			fn_print_info_nl "${backupclearcount} backups older than ${backupdays} days can be cleared."
			while true; do
				read -p "Clear older backups? [Y/N]" yn
				case $yn in
				[Yy]* ) clearoldbackups="yes"; break;;
				[Nn]* ) clearoldbackups="no"; break;;
				* ) echo "Please answer yes or no.";;
			esac
			done
			# If user wants to clear backups
			if [ "${clearoldbackups}" == "yes" ]; then
				find "${backupdir}"/ -mtime +"${backupdays}" -type f -exec rm -f {} \;
				fn_print_ok_nl "Cleared ${backupclearcount} backups."
			fi
		fi
	fi
	# Restart the server if it was stopped for the backup
	if [ "${serverstopped}" == "yes" ]; then
		command_start.sh
	fi
else
	fn_print_error_nl "Backup failed: ${backupname}.tar.gz"
	fn_script_log_error "Backup failed: ${backupname}.tar.gz"
fi
sleep 0.5
core_exit.sh<commit_msg>mainly imrpoves logging #1098<commit_after>#!/bin/bash
# LGSM command_backup.sh function
# Author: <NAME>
# Website: https://gameservermanagers.com
# Description: Creates a .tar.gz file in the backup directory.

local commandname="BACKUP"
local commandaction="Backup"
local function_selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))"

check.sh
fn_print_header
# Check if a backup is pending or has been aborted using .backup.lock
if [ -f "${tmpdir}/.backup.lock" ]; then
	fn_print_warning_nl "A backup is currently running or has been aborted."
	fn_script_log_warn "A backup is currently running or has been aborted."
	while true; do
		read -e -i "y" -p "Continue anyway? [Y/N]" yn
		case $yn in
		[Yy]* ) fn_script_log "User continues anyway"; break;;
		[Nn]* ) echo Exiting; fn_script_log "User aborted"; return;;
		* ) echo "Please answer yes or no.";;
	esac
	done
fi
fn_print_dots ""
sleep 0.5
# Prepare backup file name with servicename current date
backupname="${servicename}-$(date '+%Y-%m-%d-%H%M%S')"
# Tells how much will be compressed using rootdirduexbackup value from info_distro and prompt for continue
info_distro.sh
fn_print_info_nl "A total of ${rootdirduexbackup} will be compressed into the following backup:"
echo "${backupdir}/${backupname}.tar.gz"
while true; do
	read -e -i "y" -p "Continue? [Y/N]" yn
	case $yn in
	[Yy]* ) break;;
	[Nn]* ) echo "Exiting"; fn_script_log "User aborted"; return;;
	* ) echo "Please answer yes or no.";;
esac
done

# Check if server is started
check_status.sh
if [ "${status}" != "0" ]; then
	echo ""
	fn_print_warning_nl "${servicename} is currently running."
	
	sleep 1
	while true; do
		read -p "Stop ${servicename} while running the backup? [Y/N]" yn
		case $yn in
		[Yy]* ) command_stop.sh; serverstopped="yes"; break;;
		[Nn]* ) serverstopped="no"; break;;
		* ) echo "Please answer yes or no.";;
	esac
	done
fi

fn_print_dots "Backup in progress, please wait..."
fn_script_log_info "Started backup"
sleep 1
if [ ! -d "${backupdir}" ]; then
	mkdir "${backupdir}"
fi
# Create lockfile
touch "${tmpdir}/.backup.lock"
fn_script_log "Lockfile created"
# Compressing files
fn_script_log "Compressing ${rootdirduexbackup}".
tar -czf "${backupdir}/${backupname}.tar.gz" -C "${rootdir}" --exclude "backups" ./*
# Remove lockfile
rm "${tmpdir}/.backup.lock"
fn_script_log "Lockfile removed"
# Check tar exit code and act accordingly
if [ $? == 0 ]; then
	# Exit code doesn't report any error
	fn_print_ok_nl "Backup created: ${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
	fn_script_log_pass "Backup created: ${backupdir}/${backupname}.tar.gz is $(du -sh "${backupdir}/${backupname}.tar.gz" | awk '{print $1}') size"
	
	# Clear old backups if backupdays variable exists
	if [ -n "${backupdays}" ]; then
		# Count how many backups can be cleared
		backupclearcount=$(find "${backupdir}"/ -type f -mtime +"${backupdays}"|wc -l)
		# Check if there is any backup to clear
		if [ "${backupclearcount}" -ne "0" ]; then
			fn_print_info_nl "${backupclearcount} backups older than ${backupdays} days can be cleared."
			fn_script_log "${backupclearcount} backups older than ${backupdays} days can be cleared."
			while true; do
				read -p "Clear older backups? [Y/N]" yn
				case $yn in
				[Yy]* ) clearoldbackups="yes"; break;;
				[Nn]* ) clearoldbackups="no"; fn_script_log "User didn't clear backups"; break;;
				* ) echo "Please answer yes or no.";;
			esac
			done
			# If user wants to clear backups
			if [ "${clearoldbackups}" == "yes" ]; then
				find "${backupdir}"/ -mtime +"${backupdays}" -type f -exec rm -f {} \;
				fn_print_ok_nl "Cleared ${backupclearcount} backups."
			fi
		fi
	fi
	# Restart the server if it was stopped for the backup
	if [ "${serverstopped}" == "yes" ]; then
		command_start.sh
	fi
else
	# Exit code reports an error
	fn_print_error_nl "Backup failed: ${backupname}.tar.gz"
	fn_script_log_error "Backup failed: ${backupname}.tar.gz"
fi
sleep 0.5
core_exit.sh
{'fraction_non_alphanumeric': 0.14998651200431615, 'fraction_numerical': 0.0037766387914755866, 'mean_word_length': 4.243988684582744, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4018372', 'n_tokens_mistral': 2706, 'n_tokens_neox': 2561, 'n_words': 855}