hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Web Hosting Talk Tutorials : VPS Tutorials : How to backup your linux VPS.
Reply

Forum Jump

How to backup your linux VPS.

Reply Post New Thread In VPS Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 02-25-2012, 10:32 PM
613websites 613websites is offline
Web Hosting Guru
 
Join Date: Aug 2009
Location: Canada
Posts: 348
Thumbs up

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:

Code:
bash backup.sh
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!

__________________
613websites.com ● 1-800-636-1484
Budget Canadian Hosting and Web Design
Visit us @ www.613websites.com!



Sponsored Links
  #2  
Old 02-26-2012, 01:22 PM
prohosterz prohosterz is offline
WHT Addict
 
Join Date: Dec 2011
Location: World Wide Web
Posts: 122
nice script, thanks a lot...

  #3  
Old 04-14-2012, 03:04 PM
ac1d-dot-org ac1d-dot-org is offline
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

Sponsored Links
  #4  
Old 04-14-2012, 03:07 PM
~Lee~ ~Lee~ is offline
Ten years on this site!
 
Join Date: May 2003
Location: Scotland
Posts: 3,621
Be careful though, if you have a site with a mysql database for example this is not going to back that up.

  #5  
Old 04-17-2012, 05:42 PM
Trader5050 Trader5050 is offline
Newbie
 
Join Date: Apr 2012
Posts: 7
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?

  #6  
Old 04-17-2012, 07:05 PM
613websites 613websites is offline
Web Hosting Guru
 
Join Date: Aug 2009
Location: Canada
Posts: 348
Quote:
Originally Posted by Trader5050 View Post
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.

__________________
613websites.com ● 1-800-636-1484
Budget Canadian Hosting and Web Design
Visit us @ www.613websites.com!

  #7  
Old 04-18-2012, 05:01 PM
Vasar Vasar is offline
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.

  #8  
Old 04-19-2012, 07:17 AM
host plugin host plugin is offline
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

  #9  
Old 04-19-2012, 07:43 AM
aae55555 aae55555 is offline
Newbie
 
Join Date: Apr 2012
Posts: 21
Thanks for the script. Could prove quite handy

  #10  
Old 04-19-2012, 05:48 PM
613websites 613websites is offline
Web Hosting Guru
 
Join Date: Aug 2009
Location: Canada
Posts: 348
No problem guys!

__________________
613websites.com ● 1-800-636-1484
Budget Canadian Hosting and Web Design
Visit us @ www.613websites.com!

  #11  
Old 04-21-2012, 02:04 AM
raindog308 raindog308 is offline
Web Hosting Master
 
Join Date: Jul 2010
Posts: 769
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.

__________________
TransLantern - a Better Hosting Experience
A la Carte Pricing - LiteSpeed - cPanel - Softaculous - Financially Guaranteed Backups
Check out our hosting tutorial videos !

  #12  
Old 04-21-2012, 11:28 AM
613websites 613websites is offline
Web Hosting Guru
 
Join Date: Aug 2009
Location: Canada
Posts: 348
Quote:
Originally Posted by raindog308 View Post
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.

__________________
613websites.com ● 1-800-636-1484
Budget Canadian Hosting and Web Design
Visit us @ www.613websites.com!

  #13  
Old 04-21-2012, 12:28 PM
raindog308 raindog308 is offline
Web Hosting Master
 
Join Date: Jul 2010
Posts: 769
Quote:
Originally Posted by d4m1r View Post
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.

__________________
TransLantern - a Better Hosting Experience
A la Carte Pricing - LiteSpeed - cPanel - Softaculous - Financially Guaranteed Backups
Check out our hosting tutorial videos !

  #14  
Old 05-01-2012, 10:05 AM
613websites 613websites is offline
Web Hosting Guru
 
Join Date: Aug 2009
Location: Canada
Posts: 348
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.

__________________
613websites.com ● 1-800-636-1484
Budget Canadian Hosting and Web Design
Visit us @ www.613websites.com!

  #15  
Old 06-04-2012, 07:32 AM
miki86 miki86 is offline
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

Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup your linux VPS/server on autopilot in 3 minutes Backupteddy Other Web Hosting Related Offers 0 09-05-2011 11:13 PM
Backup your linux VPS/server with ease Backupteddy Other Web Hosting Related Offers 0 08-11-2011 09:12 PM
Linux/windows VPS starts $8.25pm. Free backup space. Daily backup. turbovps VPS Hosting Offers 3 10-14-2008 06:16 AM
DEDICATED BACKUP: Remote Backup Space for Linux & Windows. HT Special: 50% Off! dordal Other Web Hosting Related Offers 0 06-07-2006 12:23 AM
Solar VPS: Windows & Linux VPS as Low as $15.00/mo, 50% OFF 1st Month, FREE Gb Backup SolarVPS VPS Hosting Offers 0 08-08-2005 09:31 AM

Related posts from TheWhir.com
Title Type Date Posted
Sterling Data Storage Launches Three Cloud Backup Services Web Hosting News 2013-01-14 13:39:31
HostPapa Offers Backup and Disaster Recovery Services through Vembu Partnership Web Hosting News 2012-11-21 16:42:51
New BackupAgent Version Simplifies Channel Delivery of Cloud Backup Solution Web Hosting News 2012-06-26 16:57:11
Cloud City Hosting Integrates Backup with Cloud Hosting Plans Web Hosting News 2012-05-11 16:21:19
R1Soft Launches Cloud Backup Software for Web Hosting Companies Web Hosting News 2012-04-24 11:45:03


Tags
backup, d4m1r, openvz, rsync, vps

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?