H
H
hrvasiliy2015-09-03 21:13:28
Yandex.Disk
hrvasiliy, 2015-09-03 21:13:28

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

1 answer(s)
M
mureevms, 2015-09-03
@hrvasiliy

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

2. Backup of configs is also carried out using the tar command (with the current initial data, all configs are in / etc)
etc_backup.sh file:
#!/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

3. Sites are backed up in a similar way (I assume that they are in /var/www/)
File www_backup.sh:
#!/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

4. MySQL backup is performed using the mysqldump command
File mysql_backup.sh
#!/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

Restoration of sites and configs is carried out by simple copying to the destination.
Database recovery:
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

System recovery is a more complicated process, but the essence boils down to one thing - make a clean installation of a similar OS, boot from a LIVE CD, mount Yadisk and unpack the archive into the root directory (the root directory is called the root of the file system - /), except for the /boot directory, you
MUST do it in advance recovery on a separate virtual machine.
Instead of an afterword
Such a backup, as they say, can't be killed with a stick. The only thing to do is from time to time to manually check the backup archives for readability and the passage of normal unzipping. Unfortunately, the archives are broken.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question