Backup Linux

Facem un backup pe Linux cu RSYNClinux

RSYNC

Local = cel care-l salvam
Remote= cel pe care vom salva

pe remote:

apt-get -y install rsync

Creem user

adduser backup –home /home/backup

Se va introduce parola si restul pot fi blank

:~# adduser backup –home /home/backup
Adding user `backup’ …
Adding new group `backup’ (1002) …
Adding new user `backup’ (1002) with group `backup’ …
Creating home directory `/home/backup’ …
Copying files from `/etc/skel’ …
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for backupr
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y

pe local:

apt-get -y install rsync

generam cheie de ssh

ssh-keygen -t dsa

se va lasa gol pentru a fi fara pass
copiem cheia pe remote (ATENTIE, daca ne legam la userul back-up va fi mai secure dar nu va pastra owner-ul fisiereleor, pentru asta trebuie sa copiem cheia de root pe server)

ssh-copy-id -i .ssh/id_dsa.pub backup@remote.linux.ro

daca ssh este pe port diferit se foloseste comanda:

ssh-copy-id -i .ssh/id_dsa.pub “backup@remote.linux.ro -p 2323”

gata.. acum va puteti loga fara parola
si facem backup:

rsync -avzr –progress -e ssh /var/lib/mysql backup@remote.linux.ro:mysqlb

asta va sincroniza continutul fodlerului mysql cu serverul remote unde este creat folderul mysqlb
Automatizam procesul:

crontab -e

si adaugam:

0 3 * * * rsync -avzR –log-file=/var/log/rsync.cron.log -e ssh /var/lib/mysql backup@remote.linux.ro:mysqlb >> /dev/null 2>&1

Asta va face sync la fiecare 3 dim la folderul /var/lib/mysql

-a face:
Recursive mode
Preserves symbolic links
Preserves permissions
Preserves timestamp
Preserves owner and group

-z is to enable compression
-v verbose
-r indicates recursive
-u do not overwrite a file at the destination
-d synchronize only directory tree
–progress displays detailed progress
–delete deletes files that are not there in source directory
-i displays the item changes (differences)

Backup la tot linuxul:

daca e alt port se fol: -e “ssh -p 2323” / backup……

rsync -aAXv –log-file=/var/log/rsync.cron.log -e ssh / backup@remote.linux.ro:backup –exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}


Sync over FTP, Duply
Backup de pe local pe alt server folosind FTP

cd /tmp
wget http://downloads.sourceforge.net/project/ftplicity/duply%20%28simple%20duplicity%29/1.5.x/duply_1.5.11.tgz
tar xvfz duply_1.5.11.tgz
cp duply_1.5.11/duply /usr/local/bin
mkdir /etc/duply

cream cheie si tineti minte parola introdusa:

gpg –gen-key

luam decat ce ne intereseaza din ea:

gpg: key E7D23GCEA marked as ultimately trusted
public and secret key created and signed.

verificam ca exista cheia:

gpg –list-keys

acum facem setarile:

duply numebackup create
vim /etc/duply/numebackup/conf

punem cheia de mai sus:

# gpg key data (for symmetric encryption comment out GPG_KEY)
GPG_KEY='E7D23GCEA'
GPG_PW='parola_introdusa_mai_devreme_la_generarea_cheii_securizate'

se seteaza target si source


backup la totate bazele de date mysql

mysqldump -u root -p parola_dvs_de_la_mysql –all-databases –lock-tables=false -f >/home/backupdb`date +%a`.sql

facem si cron sa automatizam lucrurile:

crontab -e

si adaugam:

5 3 * * * mysqldump -u root -p parola_dvs_de_la_mysql --all-databases --lock-tables=false -f >/home/backupdb`date +%a`.sql &> /dev/null

asta va face un fisier zilnic cu toate bazele la ora 3:05 care-l va rescrie in fiecare saptamana in folderul /home

 


 

Ultimele știri linux:

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Zi cu cuvintele tale...