N
N
niocncn2014-05-06 09:56:11
linux
niocncn, 2014-05-06 09:56:11

What is the best way to organize a remote backup of a Linux server to a remote FTP?

Hello. Please advise what to use for a remote backup of server data.
I would like it to be like this. There is a machine on some kind of Linux (for example, CentOs), which I access through the usual http. A page pops up there, with a form in which you can add a certain number of servers. We press "ok" and it saves the server data, after that, once in a certain period, it climbs onto these servers and makes a backup of the database and files. Then he saves the backups at home or uploads them to some FTP.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
E
Egor Ogurtsov, 2014-05-06
@mrdubz

I've been waiting for this for a year

V
v_prom, 2014-05-06
@v_prom

um, isn't it easier to throw a script that will make a backup and transfer it to the desired ftp? it's faster and you don't need to write something in php and you don't need to set up a web server.

N
niocncn, 2014-05-06
@niocncn

I wish there was a web interface. You enter data into the form, the PHP script saves the data of the new server in some kind of file or something ... I think, add the script to cron, and substitute the server data into it. But what is the best way to do it? Here I found a script that almost completely satisfies my requirements.

#!/bin/sh

# задаем переменную DATE. Она будет содержать текущую дату.

DATE=`date +%Y-%m-%d_%H-%M-%S`

# задаем переменную содержащую путь к каталогу с бэкапами.

DIR=/home/backups/

# переходим в каталог, где должны храниться бэкапы.

cd $DIR 

# создаем дамп всей базы данных MySQL под пользователем root и сжимаем дамп.

mysqldump -uroot -hlocalhost -p'Пароль рута к БД' -A | gzip -c > mysql_all_db_$DATE.gz

# создаем tar сжатый контейнер. Т.е. архивируем каталог www. В каталоге www хранятся все мои сайты.

tar -czf home_$DATE.tar.gz -P /home/www

# дополнительный параметр -P заперщает архиватору отбрасывать корневой '/'.

# Аналогичным образом архивируем конфигурационные файлы системы, необходимые для быстрого развертывания
# сервера из бэкапа. 
# каталог httpd, nginx и т.д. Все файлы будут добавлены в архив с сохранением путей.

tar -czf configs_$DATE.tar.gz -P /etc/openvpn /etc/httpd /etc/nginx /etc/my.cnf /etc/php.ini /etc/logrotate.conf /etc/sysconfig/iptables /etc/sysconfig/clock  /var/spool/cron

# Копируем наши файлы архивов на удаленный сервер с применением
# <a href="/articles/users/generacziya-klyuchej-dlya-besparolnogo-vxoda.html"><strong>авторизации по ключу</strong></a>.
# Ключ -i говорит программе scp о том, что для идентификации используется файл "for_scp",
# который я <a href="/articles/users/generacziya-klyuchej-dlya-besparolnogo-vxoda.html">генерировал</a> ранее.

scp -B -i /root/.ssh/for_scp /home/backups/mysql_all_db_$DATE.gz [email protected]:~/backups_linux26.ru
scp -B -i /root/.ssh/for_scp /home/backups/configs_$DATE.tar.gz [email protected]:~/backups_linux26.ru
scp -B -i /root/.ssh/for_scp /home/backups/home_$DATE.tar.gz [email protected]:~/backups_linux26.ru

# удаляем 2 дневные копии архивов

find /home/backups/ -name "*.gz" -mtime 2 -exec rm -f {} \;


# инициализируем переменную freemaemory, задав ей значение процентного использования жесткого диска

freemaemory="$(df -h | grep "5.7" | awk '{ print $4 }')";

# grep "5.7" - фильтрую вывод по размеру своего жесткого диска.
# У Вас будет другое значение. Узнать размер жесткого диска можно командой df -h


# Ну и для информирования я отправляю сообщение себе на почту письмо с сообщением, о том, что натворил.
# Ключ -e позволяет echo использовать спец теги, такие как \n (перенос строки) в данном примере.



echo -e "Создание резервной копии сервера linux26.ru успешно завершено "`date`"\n\nСозданы следующие архивы:\nmysql_all_db_"$DATE".gz - Дамп базы данных\nhome_"$DATE".tar.gz - Архив web директории\nconfigs_"$DATE".tar.gz - Архив основных конфигурационных файлов системы.\n\nАрхивы отправлены на удаленный сервер.\n\n2-дневные архивы удалены.\n\nЗанято "$freemaemory" дискового пространства" | mail -s "Backup on linux26.ru complate" [email protected]

Taken from linux26.ru
Only here for one server, but I need to save data from several.

A
Alexander Kubintsev, 2014-05-07
@akubintsev

"gets into these servers and makes a backup of the database and files."
Completely wrong decision.
Backups should be done on the crown "on the spot". Moreover, to guarantee the integrity of the "base and files", the best solution is to use LVM partitions and make snapshots from them, which are then easy to archive and send to wherever you need.

I
Igor, 2014-05-06
@merryjane

If you only have servers (that is, you can install any software), you can look towards ready-made solutions with a central node. For example, bacula. It has both GUI clients and web faces.
But it was not in vain that you were advised about the scripts on the servers. If the task launch is initiated on the client (for example, by cron), then you can make sure that local copies of backups are stored. This is convenient if there are problems on the network, that is, the local backup will be 100%, but over the network it may not be filled due to any problems. The same applies to the central node, if it does not reach your client server, you will not have an up-to-date backup. And if the script runs locally on the client, and then does not reach the backup server, then only the copy on the backup server will be lost, while the local copy will lie in its place.

D
D1abloRUS, 2014-05-06
@D1abloRUS

look at backuppc.sourceforge.net

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question