LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 07-03-2018, 06:32 AM   #1
ajdin
LQ Newbie
 
Registered: Jul 2018
Posts: 3

Rep: Reputation: Disabled
Copy backup to backup server script need upgrade...


Hello,

we have script that copy weekly backup from server to backup server every week but sometimes it copy old backup.
So does anyone have idea how to check creation date of directory /backup/weekly/*/accounts and compare to current date (date that script start to copy to remote server) and send email if directory is created and backup is copy or send email that backup isn't created.
Also how to check if backup is created because sometimes cPanel create only directories not files like tar.gz or additional user directory if incremental backup is configured on server.
So it's like:
-check creation date of directory and if have content and make sure that directory isn't 10 days old and send email.
-than copy backup to backup server

Kind regards.
 
Old 07-04-2018, 06:40 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 8,745
Blog Entries: 5

Rep: Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141Reputation: 2141
Quote:
Originally Posted by ajdin View Post
So does anyone have idea how to check creation date of directory /backup/weekly/*/accounts and compare to current date (date that script start to copy to remote server) and send email if directory is created and backup is copy or send email that backup isn't created.
oh yes, many ideas.
if i was you i'd write a shell script utilizing the find command with it's various time related switches.
also sending email via command line isn't exactly rocket science.
so, search the web, look at what others made, then write your script.

you will get help here, but not before you show some effort.

and let's say it again, this isn't exactly rocket science and if you're responsible for server backups this shouldn't be hard for you at all.
 
1 members found this post helpful.
Old 07-04-2018, 06:55 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.3
Posts: 17,524

Rep: Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417
Please post (in code tags https://www.linuxquestions.org/quest...do=bbcode#code ) your current script.
 
Old 07-11-2018, 01:30 AM   #4
ajdin
LQ Newbie
 
Registered: Jul 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello,

here is what I try to make to get creation date od directory and compare current and creation date...
also I have issue with getting format of date of creation so i can compare it tu current date... here is code:
Code:
d1=$(date +%a-%b-%Y)
target="/path/to/dir"

inode=$(stat -c %i $target)
fs=$(df $target  | tail -1 | awk '{print $1}')
crtime=$(sudo debugfs -R 'stat <'"${inode}"'>' "${fs}" 2>/dev/null | grep -oP 'crtime.*--\s*\K.*')
printf "${crtime}"                  


if [ "$(( $(date +"%s") - $(date +%s --date "crtime_variable") ))" -gt "86400" ]; then
   echo older
else
   echo not older
as you can see I try to get creation time from directory and subtract from current date and compare with number of days in seconds.
can someone plesae help me to get format of date that I can compare with current (current_date - creation_date=number and is number <> than 10).

best regards.
 
Old 07-11-2018, 04:43 AM   #5
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.4
Posts: 1,199

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
The date (in seconds since epoch) of the backup file (not directory) is
Code:
date +%s -r filename
compare that to the current date/time
Code:
date +s
Please read man date...man pages are your friend

Yes, -r gives the modified date of the file rather than the create date...but that's what you want. you don't need to know when the file was created...you need to know when it was last touched.
[A large backup could have several minutes between create date and modified date...]
 
Old 07-11-2018, 04:52 AM   #6
ajdin
LQ Newbie
 
Registered: Jul 2018
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello,

in this case I want to know when folder is created in "/backup/weekly/*/accounts" witch is cpanel backup. After I get crtime I need to put it in variable and compare as you see in if statement with current date when script starts to execute.

Kind regards.
 
Old 07-11-2018, 07:58 AM   #7
Habitual
LQ 5k Club
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: High Sierra
Posts: 9,054
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by ajdin View Post
as you can see I try to get creation time from directory and subtract from current date and compare with number of days in seconds.
can someone plesae help me to get format of date that I can compare with current (current_date - creation_date=number and is number <> than 10).

best regards.
Have a look at http://www.linuxquestions.org/questi...ar-4175429139/
for possible alternate coding snippets.

Suggestion:
rsync all of
"/backup/weekly/*/accounts" ?

Then you could be fairly certain you got the right one?

sudo in your script. Running script as root?
 
Old 07-12-2018, 05:40 PM   #8
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.4
Posts: 1,199

Rep: Reputation: 402Reputation: 402Reputation: 402Reputation: 402Reputation: 402
Quote:
Originally Posted by ajdin View Post
Hello,

in this case I want to know when folder is created in "/backup/weekly/*/accounts" witch is cpanel backup. After I get crtime I need to put it in variable and compare as you see in if statement with current date when script starts to execute.

Kind regards.
In your script, crtime already is a variable containing the date you want, yes?
What happens if you put $crtime where you now have crtime_variable ?

Also 86400 seconds is only one day. Is that what you want?

Last edited by scasey; 07-12-2018 at 07:01 PM.
 
  


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
[SOLVED] Best way to copy all files from server for backup before decommission rjo98 Linux - Newbie 28 09-10-2014 01:10 PM
HOW TO MAKE backup script LINUX CentOS5 copy data to another machine ytd Linux - Newbie 8 09-30-2009 01: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 08:52 AM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM
backup server for upgrade. ncsuapex Linux - Server 10 05-05-2008 08:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 08:34 PM.

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