LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-17-2011, 08:10 AM   #1
idny
LQ Newbie
 
Registered: Jan 2011
Posts: 20

Rep: Reputation: 1
Backup in Linux help needed.


hi,

Im looking to create a backup script, so i've been reading and researching but so far nothing seems to either be specific to me, or i just simply dont understand it.

Right, so im looking for a script which will.
- at 01:00 perform a backup of only the files which have been changed in /mnt/ARRAY/tech
- to /Backups/2011
- I dont want files to be zipped, they must be browsable like a normal dir.

As this will change only the files that are changed daily i do not need a full backup,this is done manually by other means.

I've heard you need cron to schedule the script, but no idea how to.
This is the current script i have written.

Code:
#!/bin/bash
#
# Simple script to Backups Files
#
sudo rsync -a -R $/mnt/ARRAY/tech/* $/Backups/2011
echo Backup started...
exit 0
# End of script.
Is it correct? How can i make it run at 01:00 each day?

Sorry for n00b question
Thanks

Last edited by idny; 01-17-2011 at 08:11 AM.
 
Old 01-17-2011, 08:34 AM   #2
fordeck
Member
 
Registered: Oct 2006
Location: Utah
Posts: 520

Rep: Reputation: 61
In order to come up to speed on scheduling via cron, you might want to start by looking at the cron and crontab manuals. You can do this by entering the following command:

man cron

This will display the manual for cron. Look at the crontab manual which will explain the syntax for setting up your desired schedule. Again just enter the following command:

man crontab

Or more specifically:

man 5 crontab

Regards,

Fordeck
 
Old 01-17-2011, 08:51 AM   #3
idny
LQ Newbie
 
Registered: Jan 2011
Posts: 20

Original Poster
Rep: Reputation: 1
ok,

i've read through the manual

so im guessing the script now needs to be like this?

Code:
#!/bin/bash
#
# Simple script to Backups Files
#
1 1 * * * sudo rsync -a -R $/mnt/ARRAY/tech/* $/Backups/2011
echo Backup started...
exit 0
# End of script.
This will start the script at 01:01AM if im correct?
is this all thats needed?
 
Old 01-17-2011, 08:56 AM   #4
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Code:
1 1 * * * scriptname
This part goes in the crontab file, not in the script.
 
Old 01-17-2011, 09:00 AM   #5
idny
LQ Newbie
 
Registered: Jan 2011
Posts: 20

Original Poster
Rep: Reputation: 1
i see.
that makes much more sense.
thanks

I will test soon and give feedback
 
Old 01-17-2011, 01:42 PM   #6
idny
LQ Newbie
 
Registered: Jan 2011
Posts: 20

Original Poster
Rep: Reputation: 1
right...i've just done the script

and then did

Code:
sudo crontab -e

45 18 * * * sudo ./backup.sh
which was 10 mins ago

How do i know if this worked??

Last edited by idny; 01-17-2011 at 01:46 PM.
 
Old 01-17-2011, 02:48 PM   #7
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 332Reputation: 332Reputation: 332Reputation: 332
Quote:
Originally Posted by idny View Post
How do i know if this worked??
Traditionally cron jobs send mail to the user account under which it is run. You could try opening a terminal window and typing mail to see if you have mail.
Code:
mail
I would put something in the script to create a log file.

Code:
echo "Backup starting" > $HOME/backup.log

echo "Backup finished" >> $HOME/backup.log
You could make it fancier than that.

Code:
echo "Backup started at " `date` > $HOME/backup.log

echo "Backup finished at " `date` >> $HOME/backup.log

Last edited by stress_junkie; 01-17-2011 at 02:51 PM.
 
Old 01-17-2011, 03:24 PM   #8
silvyus_06
Member
 
Registered: Oct 2010
Distribution: Ubuntu 10.04 , Linux Mint Debian Edition , Microsoft Windows 7
Posts: 390

Rep: Reputation: 50
scripts are awesome!

can you please mark the thread as solved if your issue was... well .. solved?
 
Old 01-17-2011, 03:32 PM   #9
argony
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Rep: Reputation: 0
If you really want to get fancy with it, you can use 'logger' to actually log it to syslog, and even send mail from your backup script.
 
Old 01-17-2011, 03:36 PM   #10
argony
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Rep: Reputation: 0
When you use logger. the actual message that you send will be put in some file in /var/log. The actual file must be configured by modding /etc/syslog.conf.
 
Old 01-18-2011, 01:02 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,412

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
@idny: cron has a minimal $PATH, so it's highly recommended that all scripts/cmds use the full absolute path eg instead of

./backup

try

/home/me/backup

substitute relevant path to the the script. Ditto for sudo cmd etc.
 
1 members found this post helpful.
Old 01-18-2011, 06:02 AM   #12
idny
LQ Newbie
 
Registered: Jan 2011
Posts: 20

Original Poster
Rep: Reputation: 1
Hi guys.

Thanks very much for the replies. I managed to get it working using your help.
It now looks like this.

Script
Code:
#!/bin/bash
#
# Simple Backup Script
#
# This tells the script to grab the date from the system.
DATE=$TODAY(date)
echo Backup started...'date'
rsync -av /mnt/ARRAY/tech/* /sbackup/
echo "Backup finished at " `date` >> $/personal/backup.log
exit 0
# End of script
By using rsync, this checks to see if any files have changed in the /mnt/ARRAY/tech directory, and if so copies them to /sbackup/.

I then added it to crontab........sudo vi /etc/crontab

Code:
1 1 * * * root echo "Cron Check, Working..."
1 2 * * * root /sbackup/backup.sh
The echo command is just so i can see if cron is working.
and then check that cron performed the task correctly from the backuo.log

Hope this helps someone else aswell.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
The linux software "simple backup" - how backup everything? Bob Appleby Linux - Software 1 09-20-2010 12:59 AM
[SOLVED] Linux HDD backup under windows - looking for backup utility SigTerm General 1 01-27-2010 12:54 PM
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 09:52 AM
LXer: Automatic backup for sporadically connected clients with Box Backup LXer Syndicated Linux News 0 08-29-2008 09:40 PM
Backup system ala rdiff-backup, but without mirror and with dst encryption dr_dex Linux - Software 0 08-04-2008 04:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:23 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration