×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to create a backup cron script??? Plz help

How to create a backup cron script??? Plz help

How to create a backup cron script??? Plz help

(OP)
Hey,

I have a few web servers, and there is a backup cron setup in the web panel of my server to create a tarball for every website hosted on my server and save it locally to /home/backups every Saturday evening. I just installed and mounted an external hard drive to the /mnt/usbfantom directory. My goal here is to make a script that automatically copies everything from the /home/backups directory and save it to the /mnt/fantom directory on Sunday (the day AFTER the backups from the server are created) on a cron schedule. I am completely lost here. Thanks in advance for the help!

Brad L. - MCP

"If the doctors told me I had 5 minutes to live, I would type faster."

RE: How to create a backup cron script??? Plz help

It sounds like you have two problems.  First, you need to create a script to copy the backups.  That can be accomplished pretty easily, just look at the script that is running in the other cron job and adjust it as needed.  Second, you need to create another entry in the cron.tab that will actually kick off the script you just wrote.

FWIW, you might get better response in the Linux (server) forum.

RE: How to create a backup cron script??? Plz help

(OP)
This is all stuff I already know, its just how to do it. The cron that I already have I didn't create in Linux, I created it in a web-based admin panel of my hosting software installed on the server, so I'm pretty clueless as to how it needs to be done...

Brad L. - MCP

"If the doctors told me I had 5 minutes to live, I would type faster."

RE: How to create a backup cron script??? Plz help

For a simple backup, create an empty text document.
$touch mybackup.sh

Make it executable by the owner.
$chmod 755 mybackup.sh

Open in a text editor and add the following.

CODE

#!/bin/bash
rm -Rf /mnt/usbfantom/*
cp -R /home/backups/ /mnt/usbfantom/

Save it and run it to test.
$./mybackup.sh

If it works, add to a line to the crontab.
$crontab -e
0 6 * * 0 /location/of/mybackup.sh

If using vi to edit the crontab. Press the Insert key before typing. Press Escape when you're done, then type :wq and hit Enter to save and exit.

For Nano, just type as normal, then hit CTRL+O to save, press Enter when it asks, the hit CTRL+X to exit.

This will now run every Sunday at 0600 hrs. It deletes everything on /mnt/usbfantom/ then copies everything from /home/backups/ to it. If you want to create a series of backups (create folders named today's date YYYYMMDD), I'd recommend using PHP. The script is much smaller to write. I posted a shell script in the MySQL forum to backup databases and store them in the day folder format. You could use that also.

Here's a quick PHP script to do the backup with date folders.

CODE

<?php
$today = date('Ymd');
shell_exec("mkdir /mnt/usbfantom/$today");
shell_exec("cp -R /home/backups/ /mnt/usbfantom/$today/");
?>

Set up in the crontab just the same. Or to be safe, you could use...

0 6 * * 0 /usr/bin/php /location/of/mybackup.php

So it knows to use the php interpreter. You need to have php-cli installed to use it.

Mark

RE: How to create a backup cron script??? Plz help

(OP)
Thanks for the help, but to make things simpler, instead of creating a script and entering that into the crontab, I just entered the copy job right into the crontab... Below is what I entered into the crontab and it works great...

43 14 * * 7 /usr/bin/rsync -av /home/backups /mnt/usbfantom/ 1> /dev/null 2>&1

The above would copy only the new backups in /home/backups to /mnt/usbfantom/ every Sunday at 2:43PM. Thank you for the help though guys!

Brad L. - MCP

"If the doctors told me I had 5 minutes to live, I would type faster."

RE: How to create a backup cron script??? Plz help

Double-check your cron. The days of the week go from 0-6. Sunday is 0.

Mark

RE: How to create a backup cron script??? Plz help

(OP)
Actually the days go from 0-7, Sunday is both 0 and 7, whichever (I tried it over and over again, trust me)

Brad L. - MCP

"If the doctors told me I had 5 minutes to live, I would type faster."

RE: How to create a backup cron script??? Plz help

I've never tried 7. Their doc doesn't show it as valid.

I take that back, I just found some doc that shows a 7. I've never seen that before.

Learn something new every day. I guess I'm done. :)

Mark

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close