31 lines
1.1 KiB
Bash
31 lines
1.1 KiB
Bash
#!/bin/bash
|
|
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Please run as root"
|
|
exit
|
|
fi
|
|
|
|
PURPLE='\033[35m'
|
|
ORANGE='\033[33m'
|
|
BLUE='\033[34m'
|
|
BOLD='\033[1m'
|
|
RESET='\033[0m'
|
|
|
|
echo -e "${PURPLE}${BOLD}Export Directus Database and files ? (y/N) ${RESET}"
|
|
read answer
|
|
if [[ "$answer" == "y" ]]; then
|
|
site_name=$(ls /var/www/repositories/ | grep -v '^cms')
|
|
db_password=$(cat /var/www/repositories/cms*/.env | grep DB_PASSWORD | sed "s/[^']*'\([^']*\)'.*/\1/")
|
|
current_date=$(date +'%d-%m-%y_%H-%M')
|
|
export_folder="/root/content_exports/${site_name}_export_${date}"
|
|
mkdir -p "${export_folder}"
|
|
mysqldump -u directus -p"${db_password}" directus > "${export_folder}/db_${site_name}_${date}"
|
|
cp -r /var/www/repositories/cms*/uploads "${export_folder}"
|
|
tar -czf "/root/content_exports/${export_folder}.tar.gz" -C /root/content_exports/ .
|
|
|
|
ssh_port=$(cat /etc/ssh/sshd_config | grep "Port " | sed 's/^Port //')
|
|
ip=$(hostname -I)
|
|
echo -e "${PURPLE}${BOLD}You can now download the backup${RESET}"
|
|
echo -e "${BLUE}scp -P ${ssh_port} root@${ip}:/root/content_exports/${export_folder}.tar.gz ./path/to/local/folder${RESET}"
|
|
fi |