export content script 4
This commit is contained in:
parent
add5ede8f9
commit
ac82aa949e
|
@ -15,17 +15,23 @@ RESET='\033[0m'
|
||||||
echo -e "${PURPLE}${BOLD}Export Directus Database and files ? (y/N) ${RESET}"
|
echo -e "${PURPLE}${BOLD}Export Directus Database and files ? (y/N) ${RESET}"
|
||||||
read answer
|
read answer
|
||||||
if [[ "$answer" == "y" ]]; then
|
if [[ "$answer" == "y" ]]; then
|
||||||
|
user=$(getent passwd 1001 | awk -F: '{print $1}')
|
||||||
|
|
||||||
site_name=$(ls /var/www/repositories/ | grep -v '^cms')
|
site_name=$(ls /var/www/repositories/ | grep -v '^cms')
|
||||||
db_password=$(cat /var/www/repositories/cms*/.env | grep DB_PASSWORD | sed "s/[^']*'\([^']*\)'.*/\1/")
|
db_password=$(cat /var/www/repositories/cms*/.env | grep DB_PASSWORD | sed "s/[^']*'\([^']*\)'.*/\1/")
|
||||||
current_date=$(date +'%d-%m-%y_%H-%M')
|
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}"
|
mkdir -p "${export_folder}"
|
||||||
mysqldump -u directus -p"${db_password}" directus > "${export_folder}/db_${site_name}_${current_date}"
|
mysqldump -u directus -p"${db_password}" directus > "${export_folder}/db_${site_name}_${current_date}"
|
||||||
cp -r /var/www/repositories/cms*/uploads "${export_folder}"
|
cp -r /var/www/repositories/cms*/uploads "${export_folder}"
|
||||||
tar -czf "${export_folder}.tar.gz" -C /root/content_exports/ .
|
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 //')
|
ssh_port=$(cat /etc/ssh/sshd_config | grep "Port " | sed 's/^Port //')
|
||||||
ip=$(hostname -I)
|
ip=$(hostname -I)
|
||||||
echo -e "${PURPLE}${BOLD}You can now download the backup${RESET}"
|
if [[ "${ip: -1}" == " " ]]; then
|
||||||
echo -e "${BLUE}scp -P ${ssh_port} root@${ip}:${export_folder}.tar.gz ./path/to/local/folder${RESET}"
|
ip="${ip%?}"
|
||||||
|
fi
|
||||||
|
echo -e "${PURPLE}${BOLD}You can now download the backup${RESET}"
|
||||||
|
echo -e "${BLUE}scp -P ${ssh_port} ${user}@${ip}:${export_folder}.tar.gz ./path/to/local/folder${RESET}"
|
||||||
fi
|
fi
|
Loading…
Reference in New Issue