# Best way to backup whole OVZ vps?



## juan (Nov 13, 2013)

The vps provider will be migrating my vps to another location, and i just want to be cautious and ready for bacup if anything happens, what's the best way to backup the whole vps? Thanks.


----------



## nunim (Nov 13, 2013)

Well, if you're provide will make you a snapshot that's probably the easiest way.  I usually just backup my config files that are important like nginx, php, etc..

You can do tar -cxzf backup.tar.gz /   to backup the entire file system but there is going to be some files that are not exactly the same between the two.


----------



## Damian (Nov 13, 2013)

Ask them for a "quick backup". Should take them less than one minute to get the process started for you, so any provider should be willing to do so.


----------



## ComputerTrophy (Nov 13, 2013)

Damian said:


> Ask them for a "quick backup". Should take them less than one minute to get the process started for you, so any provider should be willing to do so.


^this. Migrations usually work flawlessly, though. Otherwise, better safe than sorry.


----------



## mojeda (Nov 13, 2013)

nunim said:


> Well, if you're provide will make you a snapshot that's probably the easiest way.  I usually just backup my config files that are important like nginx, php, etc..
> 
> You can do tar -cxzf backup.tar.gz /   to backup the entire file system but there is going to be some files that are not exactly the same between the two.


Until you realize you're backing up the backup file and get stuck into a backup loop.


----------



## concerto49 (Nov 13, 2013)

ComputerTrophy said:


> ^this. Migrations usually work flawlessly, though. Otherwise, better safe than sorry.


Except when there's lag, times out during the transfer and openvz has already killed your old vps.


----------



## TheLinuxBug (Nov 13, 2013)

Here are a few resources to help you out:

http://www.aboutdebian.com/tar-backup.htm

https://help.ubuntu.com/community/BackupYourSystem/TAR

Cheers!


----------



## KuJoe (Nov 14, 2013)

Here's a script I use to backup my VPSs:


```
#!/bin/bash

mysqldump -hlocalhost -uusername -ppassword database1 | gzip > /backup/db1.sql.gz
mysqldump -hlocalhost -uusername -ppassword database2 | gzip > /backup/db2.sql.gz
tar -zcf /backup/bin.tar.gz /bin
tar -zcf /backup/boot.tar.gz /boot
tar -zcf /backup/etc.tar.gz /etc
tar -zcf /backup/home.tar.gz /home
tar -zcf /backup/root.tar.gz /root
tar -zcf /backup/sbin.tar.gz /sbin
tar -zcf /backup/usr.tar.gz /usr
tar -zcf /backup/var.tar.gz /var
rsync -avz -e "ssh -p 1234 -i /root/.ssh/id_rsa" /backup/ [email protected]:/home/backupuser/server1/backup

uptime | nail -s "Automated Backup for server1 finished." [email protected]
```


----------



## devonblzx (Nov 14, 2013)

KuJoe said:


> Here's a script I use to backup my VPSs:
> 
> 
> #!/bin/bash
> ...


* Edit: I didn't realize nail worked as well.  Interesting.   Nail/mail does require mailx though (yum install mailx)

You could also use --all-databases with root access for MySQL to make one backup of every single database rather than doing it per database.


----------



## KuJoe (Nov 14, 2013)

devonblzx said:


> * Edit: I didn't realize nail worked as well.  Interesting.   Nail/mail does require mailx though (yum install mailx)
> 
> You could also use --all-databases with root access for MySQL to make one backup of every single database rather than doing it per database.


I use nail/mailx on all of my servers. I don't know why, just a habit from when I first started using linux years ago. I also got in the habit of creating a new user for each database that had only read access for backups since I don't like the idea of having my MySQL root password in plain text but in reality it doesn't matter much these days so the --all-databases route it probably better.


----------



## devonblzx (Nov 14, 2013)

KuJoe said:


> I use nail/mailx on all of my servers. I don't know why, just a habit from when I first started using linux years ago. I also got in the habit of creating a new user for each database that had only read access for backups since I don't like the idea of having my MySQL root password in plain text but in reality it doesn't matter much these days so the --all-databases route it probably better.


Making the file only readable by root would be a good step to take.   I use mailx too, I never knew that nail was an alias though.  I always used mail/mailx.


----------

