LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need help schedule back script (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-schedule-back-script-4175545588/)

Pearl123 06-17-2015 01:52 AM

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

chrism01 06-17-2015 05:17 AM

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.

Pearl123 06-17-2015 09:03 PM

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

chrism01 06-18-2015 06:46 AM

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/

TB0ne 06-19-2015 11:40 AM

Quote:

Originally Posted by Pearl123 (Post 5378472)
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.


All times are GMT -5. The time now is 05:15 PM.