LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 06-17-2015, 01:52 AM   #1
Pearl123
LQ Newbie
 
Registered: May 2013
Posts: 17

Rep: Reputation: Disabled
Need help schedule back script


Hi everyone,

Greetings.

I am new to Linux, I am doing the following to backup the logs and data.

Here

Logs are generated every 30 mins (usually size in GB for 30 mins)
log pattern are log_backup_somenumberwhere it will have connection to next file. I dont get that

Data are generated every day
data pattern are
yyyy-mm-dd_databackup_0_1
yyyy-mm-dd_databackup_1_1
yyyy-mm-dd_databackup_2_1
yyyy-mm-dd_databackup_3_1
yyyy-mm-dd_databackup_4_1
yyyy-mm-dd_databackup_5_1

Both logs and data are in different folder

In the linux crontab i am trying like below

30 05 * * * zip -r path/$(date +\%Y\%m\%d)_databackup_.zip path/$(date +\%Y\%m\%d)_databackup_*_1
* */1 * * * zip -r path/log_backup_$(date +\%Y\%m\%d)_.zip path/log_backup_*

( I want to zip all the data and log files to commonfolder.zip every hour and data one day)

00 06 * * * find /path -mtime -1 -exec rm -f {} \;

10 */1 * * * find /path -mtime -1 -exec rm -f {} \;
(10 minutes after 1 hour i want to remove the original files)


10 06 * * * mv /path/$(date +\%Y\%m\%d)_databackup_.zip /tmp/data
20 */1 * * * mv /path/log_backup_$(date +\%Y\%m\%d)_.zip /tmp/log
(20 minutes after 1 hour i want to move to some temp directory)

Now i want to copy files from temp directory windows server
using pscp.exe on the windows scheduler for every hour


back in linux

20 06 * * * rm -r /tmp/*

30 */1 * * * rm -r /tmp/*




But the whole process what i am trying to do is looking very clumsy and fear not correct. Can some one pls guide for a script solution for the above .

Thanks a lot for the patience

Regards
pearl
 
Old 06-17-2015, 05:17 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,295

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
A point about '*/1'; this is redundant as it means effectively the same as '*' ie take every legal value; in your case every hour.

'*' in the minute field (ie 1st field) means do it every minute; probably not what you want.

Don't delete /tmp/* as the /tmp dir is used by the system to store many temp files (other than your app) - take a look some time

Personally I wouldn't put complex cmds like that in cron anyway; the common convention is to write bash scripts that do what you want and call them.
 
Old 06-17-2015, 09:03 PM   #3
Pearl123
LQ Newbie
 
Registered: May 2013
Posts: 17

Original Poster
Rep: Reputation: Disabled
Hi Chris,

Thank you for your reply.

How would I go for writing in the bash script because I am not familiar with it. Please guide.

Regards
Pearl
 
Old 06-18-2015, 06:46 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,295

Rep: Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358Reputation: 2358
Writing shell scripts is a key skill, try the following...
The first is a tutorial in increasing skill, the others are more like references (by example) but easy to read and well worth doing so.
Enjoy

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
1 members found this post helpful.
Old 06-19-2015, 11:40 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 18,504

Rep: Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992Reputation: 3992
Quote:
Originally Posted by Pearl123 View Post
Hi everyone,
I am new to Linux,
...except you've been here for two years now....
Quote:
I am doing the following to backup the logs and data. Logs are generated every 30 mins (usually size in GB for 30 mins)
log pattern are log_backup_somenumberwhere it will have connection to next file. I dont get that

Data are generated every day
data pattern are
yyyy-mm-dd_databackup_0_1
yyyy-mm-dd_databackup_1_1
yyyy-mm-dd_databackup_2_1
yyyy-mm-dd_databackup_3_1
yyyy-mm-dd_databackup_4_1
yyyy-mm-dd_databackup_5_1

Both logs and data are in different folder

In the linux crontab i am trying like below

30 05 * * * zip -r path/$(date +\%Y\%m\%d)_databackup_.zip path/$(date +\%Y\%m\%d)_databackup_*_1
* */1 * * * zip -r path/log_backup_$(date +\%Y\%m\%d)_.zip path/log_backup_*

( I want to zip all the data and log files to commonfolder.zip every hour and data one day)

00 06 * * * find /path -mtime -1 -exec rm -f {} \;

10 */1 * * * find /path -mtime -1 -exec rm -f {} \;
(10 minutes after 1 hour i want to remove the original files)


10 06 * * * mv /path/$(date +\%Y\%m\%d)_databackup_.zip /tmp/data
20 */1 * * * mv /path/log_backup_$(date +\%Y\%m\%d)_.zip /tmp/log
(20 minutes after 1 hour i want to move to some temp directory)

Now i want to copy files from temp directory windows server
using pscp.exe on the windows scheduler for every hour


back in linux

20 06 * * * rm -r /tmp/*
30 */1 * * * rm -r /tmp/*

But the whole process what i am trying to do is looking very clumsy and fear not correct. Can some one pls guide for a script solution for the above.
Please read the LQ Rules about text speak, and about not using it...after two years, you should know. We will be very happy to HELP you with a script, but we are NOT GOING TO WRITE IT FOR YOU. Post what YOU have written/tried so far, and tell us where you're stuck.
 
  


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
how to schedule a script in linux farnaw4u Linux - Newbie 5 03-07-2010 06:31 PM
Using crontab to schedule a script stuball Linux - Server 9 05-19-2009 07:39 AM
Schedule a script to run philipo Slackware 3 06-22-2007 05:10 PM
Schedule a Script to Run nutthick Linux - Newbie 8 02-02-2005 12:37 PM
Schedule a script every three hours dkochan Linux - General 1 03-07-2004 10:18 AM


All times are GMT -5. The time now is 08:41 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