Answer the question
In order to leave comments, you need to log in
How to save backups to the server through the console?
When I'm done with a site, for today or in general, I run a simple script that commits to the git server and creates two files (a database and a site archive).
I want to slightly expand the functionality of the script, but I don’t know which side to approach.
What we have now, for committing to git and archiving:
#!/bin/bash
# делаем бэкап базы данных в папку проекта
sudo mysqldump -u`head -1 mysql.txt | tail -1` -p`head -2 mysql.txt | tail -1` `head -1 mysql.txt | tail -1` > `head -1 mysql.txt | tail -1`.sql
# декодируем базу в нормальную кодировку
sudo grep -rl utf8mb4 `head -1 mysql.txt | tail -1`.sql | xargs perl -p -i -e 's/utf8mb4/utf8/g'
# меняем права и владельца на конечный файл
sudo chown sergey:sergey -R `head -1 mysql.txt | tail -1`.sql
sudo chmod -R 644 `head -1 mysql.txt | tail -1`.sql
# добавляем изменения в git
git add --ignore-removal .
git commit -a -m "$(date +"%Y-%m-%d %H:%M")"
git push origin master
# записываем файлы из директории в архив
tar -cvpzf archive.tar.gz --exclude='node_modules' --exclude='.git' --exclude='archive.sh' --exclude='gitcommit.sh' --exclude='gulpfile.js' --exclude='mysql.txt' --exclude='package.json' --exclude='.gitignore' --exclude='*.sql' --exclude='*.tar.gz' * .htaccess
Answer the question
In order to leave comments, you need to log in
It is quite difficult to answer in the "blind to the deaf" mode, because It's not entirely clear what exactly is not working for you ... but, let's try.
In order not to enter a password - use authorization by key. Information on this topic, just a breakthrough, for example here (the first link that came across).
If the name $sitename is already passed to the script, I don't see any problem with using it.
At the same time, I don’t want to make a dump out of the archives folder, it is necessary that no more than 3 backup copies be stored in the folder of each site, that is, old files need to be overwritten somehow if the 4th archive is already being recorded.After connecting via SSH - count the number of files in the folder, you can also pre-sort them in direct or reverse order by date, and then delete all files according to the list, whose index in the array is greater / less than 2 or 3.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question