Answer the question
In order to leave comments, you need to log in
How to set up backup VDS on Yandex.Disk?
I can't figure out how to set up backup VDS on Yandex.Disk. I read a lot of articles, including habr (either old or not working). Got one normal article. The point is that no additional installation of any utilities is required on a server like "davfs2". And just getting a token and using it in a cron script. Only now the script is not working, but with writing scripts on the bash, there are problems.
I'm trying to backup both the sites on the server and the database + VDS settings and utilities (as for the latter, I don't even know what specifically needs to be backed up + how to recover in case something happens).
Answer the question
In order to leave comments, you need to log in
Preface.
You must mount Yadisk as described in this article to the /mnt/yadisk directory, all backups will be copied there.
To backup the entire system, it is better to use the tools offered by the hoster. If there are none or you plan to move the entire system, then use step 1.
I specially leave one copy of each backup on VDS for the convenience of restoring any file.
I will only comment on the first file, the rest are made in the likeness.
Directories in /home/backup/... and /mnt/yadisk/... should be created.
The backup script is divided into 4 pieces intentionally for ease of use and launch by cron at different time intervals, which will need to be done separately.
Also, I advise you to check whether Yadisk is mounted before backup, otherwise the place may suddenly run out on the server. If you are interested, then I will give a link on how to do it.
1. System backup is performed using the tar command
System_backup.sh file:
#!/bin/sh
TIME=`date +%Y-%m-%d`
# Что бэкапить
WHAT=/
# Куда класть бэкап
WHERE=/home/backup/system
# Куда копировать бэкап
COPY=/mnt/yadisk/system
# Бэкап системы. Файл бэкапа исключает системные каталоги и каталоги куда кладутся сами бэкапы
tar -cpzf $WHERE/$TIME.tgz --exclude=/dev --exclude=/proc --exclude=/lost+found --exclude=/home/backup --exclude=/mnt /
# Скопировать на файл бэкапа на Ядиск
cp $WHERE/$TIME.tgz $COPY
### Удалить старые файлы бэкапов
# Оставить на VDS только последний
find $WHERE -mtime +1 -print -delete
# Удалить с Ядиска бэкапы месячной давности
find $COPY -mtime +30 -print -delete
#!/bin/sh
TIME=`date +%Y-%m-%d-%H:%M`
WHAT=/etc
WHERE=/home/backup/etc
COPY=/mnt/yadisk/etc
tar -cpzf $WHERE/$TIME.tgz $WHAT
cp $WHERE/$TIME.tgz $COPY
find $WHERE -mtime +1 -print -delete
find $COPY -mtime +30 -print -delete
#!/bin/sh
TIME=`date +%Y-%m-%d-%H:%M`
WHAT=/var/www
WHERE=/home/backup/www
COPY=/mnt/yadisk/www
tar -cpzf $WHERE/$TIME.tgz $WHAT
cp $WHERE/$TIME.tgz $COPY
find $WHERE -mtime +1 -print -delete
find $COPY -mtime +30 -print -delete
#!/bin/sh
TIME=`date +%Y-%m-%d`
# Логин пользователя мускула
USER=root
# Пароль пользователя мускула
PASS=root_password
WHERE=/home/backup/mysql
COPY=/mnt/yadisk/mysql
### Базы которые надо бэкапить
for base in base_name1 base_name2
do
# Сделать дамп баз
mysqldump -u$USER -p$PASS -B $base > $WHERE/$base-$TIME.sql
done
cp $WHERE/$base-$TIME.sql $COPY
find $WHERE -mtime +1 -print -delete
find $COPY -mtime +30 -print -delete
mysql -u root -p root_password -f base_name1 < /home/backup/mysql/base_name1.sql
mysql -u root -p root_password -f base_name2 < /home/backup/mysql/base_name2.sql
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question