
02-25-2012, 10:32 PM
|
|
Web Hosting Guru
|
|
Join Date: Aug 2009
Location: Canada
Posts: 340
|
|
How to backup your linux VPS.
Hello, the below bash script will copy all files and directories on your linux VPS. I found it online after trying other linux backup options which either sucked or required me to be the server administrator.
The below scripts is for people who are on a shared node but have root access to their VPS. I'd call the file backup.sh and to run it, use:
Full script:
Code:
#!/bin/sh
####################################
#
# Backup to NFS mount script.
#
####################################
# What to backup.
backup_files="/"
# Where to backup to.
dest="/home/backup"
# Create archive filename.
day=$(date +%A)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file"
date
echo
# Backup the files using tar.
tar czf $dest/$archive_file $backup_files
# Print end status message.
echo
echo "Backup finished"
date
# Long listing of files in $dest to check file sizes.
ls -lh $dest
It creates 1 compressed .tar file locally you can then download over SSH or FTP to your PC. For reference, I have a Ubuntu 11.04 OpenVZ VPS and it created a 470MB .tar file out of ~600MB. You can specify only certain directories for backup by changing backup_files, or leaving it to "/" will backup everything.
Say thanks if this helped you!
|

02-26-2012, 01:22 PM
|
|
WHT Addict
|
|
Join Date: Dec 2011
Location: World Wide Web
Posts: 122
|
|
nice script, thanks a lot...
|

04-14-2012, 03:04 PM
|
|
Newbie
|
|
Join Date: Jul 2010
Posts: 23
|
|
how about using wput to save it on another server? a server or vps that is just for backing up
|

04-14-2012, 03:07 PM
|
|
The time is near...
|
|
Join Date: May 2003
Location: Scotland
Posts: 3,399
|
|
Be careful though, if you have a site with a mysql database for example this is not going to back that up.
|

04-17-2012, 05:42 PM
|
|
Newbie
|
|
Join Date: Apr 2012
Posts: 5
|
|
Doesn't MySQL simply store the databases as files on the disk? How would this not back them up?
Since he's starting from "/" I thought it would hit every file on the server?
|

04-17-2012, 07:05 PM
|
|
Web Hosting Guru
|
|
Join Date: Aug 2009
Location: Canada
Posts: 340
|
|
Quote:
Originally Posted by Trader5050
Doesn't MySQL simply store the databases as files on the disk? How would this not back them up?
Since he's starting from "/" I thought it would hit every file on the server?
|
It will, but for MySQL, I'd recommend manually exporting the DB seperately to keep it in tact and in a format that allows you to reimport it.
|

04-18-2012, 05:01 PM
|
|
Newbie
|
|
Join Date: Mar 2010
Posts: 11
|
|
How to make everyday backup? I have vps, but have no idea how to configurate backup process on it.
|

04-19-2012, 07:17 AM
|
|
WHT Addict
|
|
Join Date: Sep 2006
Location: Toronto
Posts: 158
|
|
@Vasar you can simply setup a cron job to backup everyday at a specific time
@d4m1r thanks for the script 
|

04-19-2012, 07:43 AM
|
|
Newbie
|
|
Join Date: Apr 2012
Posts: 21
|
|
Thanks for the script. Could prove quite handy 
|

04-19-2012, 05:48 PM
|
|
Web Hosting Guru
|
|
Join Date: Aug 2009
Location: Canada
Posts: 340
|
|
|

04-21-2012, 02:04 AM
|
|
Web Hosting Master
|
|
Join Date: Jul 2010
Posts: 704
|
|
To backup MySQL, you need to use mysqldump. Otherwise, the database may not be consistent.
I don't understand "other linux backup options which either sucked or required me to be the server administrator". In the above script, you need to have root, since you're backing up from /, right?
There's all sorts of linux backup options that don't suck - rsync on the other side (rotating directories to provide versioning), bacula, rsnapshot, spideroak, etc.
But yes, I usually roll my own, too :-)
Also, don't you need to exclude /home/backup from your tarball...otherwise you're including it in every backup, which seems pointless. There are plenty of other files that should be excluded - /tmp, /dev, /var/lib/mysql (since you should dump), etc.
You might also capture some configuration info first - e.g., dpkg -l or rpm -qa, etc.
Not to knock the script - it's a good start.
|

04-21-2012, 11:28 AM
|
|
Web Hosting Guru
|
|
Join Date: Aug 2009
Location: Canada
Posts: 340
|
|
Quote:
Originally Posted by raindog308
To backup MySQL, you need to use mysqldump. Otherwise, the database may not be consistent.
I don't understand "other linux backup options which either sucked or required me to be the server administrator". In the above script, you need to have root, since you're backing up from /, right?
There's all sorts of linux backup options that don't suck - rsync on the other side (rotating directories to provide versioning), bacula, rsnapshot, spideroak, etc.
But yes, I usually roll my own, too :-)
Also, don't you need to exclude /home/backup from your tarball...otherwise you're including it in every backup, which seems pointless. There are plenty of other files that should be excluded - /tmp, /dev, /var/lib/mysql (since you should dump), etc.
You might also capture some configuration info first - e.g., dpkg -l or rpm -qa, etc.
Not to knock the script - it's a good start.
|
Totally agree, but the point was just to post a blank script that people can edit themselves, based on their needs. No point posting a finished product when its subjective to how they will use it. Should have excluded the backup folder by default though.
As for the other options, yes I have root access, but I was talking about rsync and rsnapshot. Seems like you cannot set either of those up without being the system administrator of the node (having root access to 1 of the VPS' is not enough) as you need access to specific commands that even root doesn't have.
|

04-21-2012, 12:28 PM
|
|
Web Hosting Master
|
|
Join Date: Jul 2010
Posts: 704
|
|
Quote:
Originally Posted by d4m1r
As for the other options, yes I have root access, but I was talking about rsync and rsnapshot. Seems like you cannot set either of those up without being the system administrator of the node (having root access to 1 of the VPS' is not enough) as you need access to specific commands that even root doesn't have.
|
I backup all of my VPSes via rsync, under both OvZ and KVM. I only have root on the VPS, not the physical node.
If you have root on your VPS, that's all you need. Perhaps you need to open the rsync port in iptables.ipf? Just guessing. But anyway, it's certainly very possible.
|

05-01-2012, 10:05 AM
|
|
Web Hosting Guru
|
|
Join Date: Aug 2009
Location: Canada
Posts: 340
|
|
For those that wish to move their VPS to another server, you might want to use:
Code:
/bin /boot /etc /home /lib /media /mnt /opt /root /sbin /selinux /src /sys /tmp /usr /var
where backup_files=. Doing that will exclude /dev and /proc which will likely break the new server when restoring the backup, especially if the configuration or node hardware is different.
|

06-04-2012, 07:32 AM
|
|
New Member
|
|
Join Date: Jun 2012
Posts: 0
|
|
Hello
/dev and /proc are the system directories and they differ from OS to OS and hardware difference?
Any other important directory that should be excluded?
Thanks
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|