?
Solved

backup

Posted on 2006-11-21
6
Medium Priority
?
241 Views
Last Modified: 2010-04-20
hello,
I would like to create a very simple script to backup my websites!!
this is what I normally do each line by hand

cd /home/virtual/domain1.com/var/www
tar czf domain1.tar.gz html
tar czf domain1_cgi-bin.tar.gz cgi-bin

cd /home/virtual/domain2.com/var/www
tar czf domain2.tar.gz html
tar czf domain2_cgi-bin.tar.gz cgi-bin

cd /home/virtual/domain3.com/var/www
tar czf domain3.tar.gz html
tar czf domain3_cgi-bin.tar.gz cgi-bin

is there a way to automate that process?
if so I want to run each line after the other,
 not all at the same time, I want to keep the server load
very low so when the first backup finishes I want
to do domain2 and so on, when the process finishes
I would like to receive an email sent by sendmail!

can someone please help me?
0
Comment
Question by:Sabrin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 10

Expert Comment

by:ssvl
ID: 17993607
first you have to create a script  

add all the above backup commands to that script ( by default script runs one command after one)

for eg you want to run the backup at 1 am every day.
run as root
#crontab -e

1 1 * * *  sh /path/to/script



0
 
LVL 14

Expert Comment

by:ppfoong
ID: 17993631

Create a script and put it in /usr/local/bin.

Let's call it backupsite.sh.

The content should be:

#!/bin/sh
tar czf $1.tar.gz /home/virtual/$1.com/var/www
tar czf $1_cgi-bin.tar.gz /home/virtual/$1.com/var/cgi-bin

Then, create another script, call it mybackup.sh.

#!/bin/sh
/usr/local/bin/backupsite.sh domain1
/usr/local/bin/backupsite.sh domain2
/usr/local/bin/backupsite.sh domain3


But as a better alternative, which is able to automate the backup process as well as send out email to you, you can make use of rdiff-backup.

http://www.nongnu.org/rdiff-backup/

The backup command will be (create the /backup directory first):

rdiff-backup --print-statistics /home/virtual /backup > /tmp/backup.statisticfile
mail youremail@address.com -s "Backup result" < /tmp/backup.statisticfile

0
 
LVL 8

Accepted Solution

by:
John Kawakami earned 2000 total points
ID: 18000545
The most straightforward way is to turn your commands into a script.  Paste the following into a shell window:

----------------------------------------------------------start--------
cat > backup.sh
#!/bin/sh
cd /home/virtual/domain1.com/var/www
tar czf domain1.tar.gz html
tar czf domain1_cgi-bin.tar.gz cgi-bin

cd /home/virtual/domain2.com/var/www
tar czf domain2.tar.gz html
tar czf domain2_cgi-bin.tar.gz cgi-bin

cd /home/virtual/domain3.com/var/www
tar czf domain3.tar.gz html
tar czf domain3_cgi-bin.tar.gz cgi-bin

echo backup ran
----------------------------------------------------------end--------

Then do this:
chmod u+x backup.sh

Then read the man page for cron and crontab, and add this line:

1 3 * * * /path/to/backup.sh

That should run the backup script at 3AM daily, and send you an email about it.  (Cron automatically sends emails.  If it doesn't read the cron manpage for info about how to do that.)

Rdiff is good if you want live copies of the backup files.

Also, look into archivers that can selectively update files within the backup archive.  Read the gnu tar man page.
0
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 

Author Comment

by:Sabrin
ID: 18000674
thanks jk2001, will your code run the backups one by one ?
0
 

Author Comment

by:Sabrin
ID: 18000675
jk2001, when the tar is done with domain1 then it goes to domain2?
0
 
LVL 8

Expert Comment

by:John Kawakami
ID: 18002815
yes.  it's a "replay" of what you typed.

Also, before you put it in the cron, run the script from the command line and see that it works without errors.

ppfoong's solution is more flexible, but mine is the kind I'd normally use.  I prefer the literal code sometimes.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question