Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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. I found some similar threads, but nothing that I could figure out to make work with what I need. Thanks in advance for the help!
...What do I do with this code? Where do I put it? Excuse my ignorance, I'm pretty new to linux. And what do you mean by "would copy only the new backups"? Do you mean only the backups (or files within the /home/backups directory) that have been changed will be copied? A new baackup is created for each domain regardless, so I'm pretty sure everything would be changed weekly, whether the website itself changed or not as it makes a new tarball with every cron backup.
...What do I do with this code? Where do I put it? Excuse my ignorance, I'm pretty new to linux. And what do you mean by "would copy only the new backups"? Do you mean only the backups (or files within the /home/backups directory) that have been changed will be copied? A new baackup is created for each domain regardless, so I'm pretty sure everything would be changed weekly, whether the website itself changed or not as it makes a new tarball with every cron backup.
Yep, rsync would just keep what's changed, 'in sync' with what's elsewhere. You specify the 'master', and where to copy it. That's a pretty slick cron entry too, BTW, trickykid.
To put this in your cron file, brokenhalo, first SU to root. Then, make sure your default editor is VI, by typing in "export EDITOR=vi", then type in "crontab -e". This will bring up your cron (job scheduler) file. If you don't have one, it will create a new one for you. Put the entry in as shown, but modify it as needed. This page
The above would copy only the new backups in /home/backups to /mnt/usbfantom/ every Sunday at 10AM.
In the code you posted above, is there supposed to be a / directly after /mnt/usbfantom??? It just looks fishy... Also, If i want to test this right now to make sure it works, what would I change the 7 to??? Technically, isn't 1 Sunday (Sunday is the first day of the week)???? Also (sorry for all the questions) if I wanted to make the time, say, 10:42... How do I make that happen?
Last edited by brokenhalo; 09-26-2008 at 02:55 PM.
In the code you posted above, is there supposed to be a / directly after /mnt/usbfantom??? It just looks fishy... Also, If i want to test this right now to make sure it works, what would I change the 7 to??? Technically, isn't 1 Sunday (Sunday is the first day of the week)???? Also (sorry for all the questions) if I wanted to make the time, say, 10:42... How do I make that happen?
Not necessarily. You can put a trailing / or not but Linux knows what is and what isn't a directory, etc. Either way would work.
I always seem to use 7 instead of 0 cause while at work, the start of the week is always Monday for me and Sunday is the last day of the week when it comes to backups. Just my own rule of thumb I've kept over the years.
As for changing to test, here are what the fields represent:
MIN HOUR DOM(Day of month) MONTH DOW(Day of week)
Also for DOW, you can actually use names instead of Numbers if that makes it easier to remember.
Here's what you could do to change it to what you specified:
Yep, rsync would just keep what's changed, 'in sync' with what's elsewhere. You specify the 'master', and where to copy it. That's a pretty slick cron entry too, BTW, trickykid.
Thanks. Yeah, if you can do it in a one liner, no reason to ever create a separate script for it if it's gonna be a cron job.
One last thing... Tried to make the crontab and got this...
[root@host ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
"/tmp/crontab.XXXXUmMqZH":2: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit? y
crontab: installing new crontab
One last thing... Tried to make the crontab and got this...
[root@host ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
"/tmp/crontab.XXXXUmMqZH":2: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit? y
crontab: installing new crontab
What the hell does all this mean???
Well, you don't have a root crontab, so it created one (note above where I mentioned that earlier).
Chances are, your editor is set to ed, which IS a user-friendly editor...it's just very picky about who its friends are. The "export EDITOR=vi" line I mentioned, puts you into the VI editor, ready to create/edit your crontab file.
Well, I DID follow your direction, all except for "export EDITOR=vi" I changed to nano instead (I hate vi with a passion and love nano ) What I find odd is that it created the cron in the /tmp directory... I really need to test this out, so I want to change the date to today (what is the number?) and I need to change the time to 5 minutes from now (how do I do minutes in the time field?). Please, any help would be great so I cna leave today and know that the backups are being made... Thanks!
Well, I DID follow your direction, all except for "export EDITOR=vi" I changed to nano instead (I hate vi with a passion and love nano ) What I find odd is that it created the cron in the /tmp directory... I really need to test this out, so I want to change the date to today (what is the number?) and I need to change the time to 5 minutes from now (how do I do minutes in the time field?). Please, any help would be great so I cna leave today and know that the backups are being made... Thanks!
I went back and edited my other post that would define what you would use to test today. Just change the time and follow my chart of the day of week. I don't know what timezone you are in or country for that matter.
when I type the command crontab -e, does it create a new crontab every time? If it does, how do I delete the old ones? If it doesn't, how do I create new ones? (I'm almost done with the questions guys, bear with me ) Thanks a million! You guys are so much help, I can't thank you enough
when I type the command crontab -e, does it create a new crontab every time? If it does, how do I delete the old ones? If it doesn't, how do I create new ones? (I'm almost done with the questions guys, bear with me ) Thanks a million! You guys are so much help, I can't thank you enough
No it doesnt, you just add new lines to it. One crontab could arguably have many lines, each doing something different at a different time.
To delete a job, just either remove the line, or prefix it with a # (i.e. comment out that line)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.