From ac82aa949e5af9788d536ab13e098101360d2ffb Mon Sep 17 00:00:00 2001 From: Valentin Date: Tue, 16 Apr 2024 16:17:54 +0200 Subject: [PATCH] export content script 4 --- utils/export-content.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/export-content.sh b/utils/export-content.sh index f7df997..12cf904 100644 --- a/utils/export-content.sh +++ b/utils/export-content.sh @@ -15,17 +15,23 @@ RESET='\033[0m' echo -e "${PURPLE}${BOLD}Export Directus Database and files ? (y/N) ${RESET}" read answer if [[ "$answer" == "y" ]]; then + user=$(getent passwd 1001 | awk -F: '{print $1}') + 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_${current_date}" + export_folder="/home/val/content_exports/${site_name}_export_${current_date}" mkdir -p "${export_folder}" mysqldump -u directus -p"${db_password}" directus > "${export_folder}/db_${site_name}_${current_date}" cp -r /var/www/repositories/cms*/uploads "${export_folder}" tar -czf "${export_folder}.tar.gz" -C /root/content_exports/ . + chown -R "${user}:${user}" "${export_folder}" ssh_port=$(cat /etc/ssh/sshd_config | grep "Port " | sed 's/^Port //') ip=$(hostname -I) + if [[ "${ip: -1}" == " " ]]; then + ip="${ip%?}" + fi echo -e "${PURPLE}${BOLD}You can now download the backup${RESET}" - echo -e "${BLUE}scp -P ${ssh_port} root@${ip}:${export_folder}.tar.gz ./path/to/local/folder${RESET}" + echo -e "${BLUE}scp -P ${ssh_port} ${user}@${ip}:${export_folder}.tar.gz ./path/to/local/folder${RESET}" fi \ No newline at end of file