From dbb04e66af74dd7a09974fe3e7822089d33ef58e Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 31 May 2024 12:38:09 +0200 Subject: [PATCH] =?UTF-8?q?ajout=20du=20syst=C3=A8me=20de=20backup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++++-- assets/backup.sh | 29 +++++++++++++++++++++++++++++ bin/setup_backup.sh | 24 ++++++++++++++++++++++++ install.sh | 7 +++++++ 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 assets/backup.sh create mode 100644 bin/setup_backup.sh diff --git a/README.md b/README.md index 0a1ac3d..e0f58fb 100644 --- a/README.md +++ b/README.md @@ -44,8 +44,9 @@ Tested and optimised for [OVH VPS Starter](https://www.ovhcloud.com/fr/vps/cheap 8. Install Node 9. Prompt for the url 10. Install and run Directus -11. Install and run the front-end -12. Setup a webhook +11. Setup backup +12. Install and run the front-end +13. Setup a webhook ## Post-install @@ -76,6 +77,13 @@ Branch filter prod Authorization Header generate a safe string using : openssl rand -base64 32 ``` +4. Setup Matomo tracking + +Add a new website to track from the Matomo interface as an admin user + +All website → Add a new Website → Website + + ## Ref [Debian Web Server](https://figureslibres.io/gogs/bachir/debian-web-server) diff --git a/assets/backup.sh b/assets/backup.sh new file mode 100644 index 0000000..2fade87 --- /dev/null +++ b/assets/backup.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +receiving_ip= +receiving_user= +receiving_port= + +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="~/backup/${site_name}_export_${current_date}" + +mkdir -p "${export_folder}" + +mysqldump -u directus -p"${db_password}" directus > "${export_folder}/db_${site_name}_${current_date}.sql" +cp -r /var/www/repositories/cms*/uploads "${export_folder}" +cp -r /var/www/repositories/cms*/.env "${export_folder}" + +tar -czf "${export_folder}.tar.gz" -C ~/backup/ . + +ssh -p $receiving_port $receiving_user@$receiving_ip << 'EOF' + +mkdir -p "~/backups/${site_name}" +ls -tp "~/backups/${site_name}" | grep -v '/$' | tail -n +3 | xargs -I {} rm -- {} + +EOF + +scp -P $receiving_port "~/backup/${export_folder}.tar.gz" "${receiving_user}@${receiving_ip}:~/backups/${site_name}" +rm -r ~/backup/ \ No newline at end of file diff --git a/bin/setup_backup.sh b/bin/setup_backup.sh new file mode 100644 index 0000000..5ada048 --- /dev/null +++ b/bin/setup_backup.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +echo -e "${PURPLE}${BOLD}Enter the receiving server ip : ${RESET}" +read -s receiving_ip +echo -e "${PURPLE}${BOLD}Enter the receiving server user : ${RESET}" +read -s receiving_user +echo -e "${PURPLE}${BOLD}Enter the receiving server port : ${RESET}" +read -s receiving_port + +ssh-keygen +ssh-copy-id -p ${receiving_port} ${receiving_user}@${receiving_ip} + +install_pkg cron + +cp ../assets/backup.sh ~/backup.sh +chmod +x ~/backup.sh + +sed -i "s/^receiving_ip=.*/receiving_ip=$receiving_ip/" ~/backup.sh +sed -i "s/^receiving_user=.*/receiving_ip=$receiving_user/" ~/backup.sh +sed -i "s/^receiving_port=.*/receiving_ip=$receiving_port/" ~/backup.sh + +cronjob="0 2 * * * ~/backup.sh" + +(crontab -l | grep -F ~/backup.sh) && echo "Cron job already exists" || (crontab -l; echo "$cronjob") | crontab - \ No newline at end of file diff --git a/install.sh b/install.sh index a99c28a..13b4efd 100644 --- a/install.sh +++ b/install.sh @@ -97,6 +97,13 @@ if [[ "$answer" == "y" ]]; then . bin/install_directus.sh fi +# BACKUP +echo -e "${PURPLE}${BOLD}Setup backup ? (y/N) ${RESET}" +read answer +if [[ "$answer" == "y" ]]; then + . bin/setup_backup.sh +fi + # NUXT STATIC echo -e "${PURPLE}${BOLD}Install the front-end ? (y/N) ${RESET}" read answer