Posted on 2006-11-21
Last Modified: 2010-04-20
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/
tar czf domain1.tar.gz html
tar czf domain1_cgi-bin.tar.gz cgi-bin

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

cd /home/virtual/
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?
Question by:Sabrin
LVL 10

Expert Comment

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

LVL 14

Expert Comment

ID: 17993631

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

Let's call it

The content should be:

tar czf $1.tar.gz /home/virtual/$
tar czf $1_cgi-bin.tar.gz /home/virtual/$

Then, create another script, call it

/usr/local/bin/ domain1
/usr/local/bin/ domain2
/usr/local/bin/ 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.

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

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


Accepted Solution

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

cat >
cd /home/virtual/
tar czf domain1.tar.gz html
tar czf domain1_cgi-bin.tar.gz cgi-bin

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

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

echo backup ran

Then do this:
chmod u+x

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

1 3 * * * /path/to/

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.
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)


Author Comment

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

Author Comment

ID: 18000675
jk2001, when the tar is done with domain1 then it goes to domain2?

Expert Comment

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.

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now