Help Needed for creating the folder by checking today's date and, take backup using rsync command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help Needed for creating the folder by checking today's date and, take backup using rsync command
# 1  
Old 06-10-2019
Help Needed for creating the folder by checking today's date and, take backup using rsync command

How to create a shell script to create a folder by using the today's date to take backup using rsync command on every evening around 7 pm.
Kindly help.
Thanks.

To be more precise,
I want to create a script which matches the today's date with server's date format, if matches then creates the folder named date itself in the mentioned path "/tmp/test/files/testing/".
Moreover, after that it searches for the files which are created by today's date by using find command -newermt from some path, lets say "/var/www/path" and rsync command those files into /mnt/.

I'm kinda new shell scripter however, kindly help me with the script.

Thanks,
Bakula

Last edited by bakula10; 06-10-2019 at 08:40 AM..
# 2  
Old 06-10-2019
We will help you.
But did you try something ?

If using rsync, examine its options carefully.
Perhaps issuing a find first using absolute path, print its output to file then processes it with rsync
Code:
--files-from=FILE       read list of source-file names from FILE

Or just mkdir and rsync into it, without find execution.

What do you think?

Regards
Peasant
# 3  
Old 06-11-2019
This should get you pretty close.

Code:
F_LOC=/tmp/test/files/testing
S_LOC=/var/www/path
R_FILE=/tmp/reffile.$$

trap "rm -f \"${R_FILE}\"" EXIT HUP INT QUIT

today=$(date +%Y%m%d)
touch -t ${today}0000 "${R_FILE}"
[ -d "${F_LOC}/$today" ] || mkdir -p "${F_LOC}/$today"
cd "${F_LOC}"
(  
  cd "${S_LOC}"
  find . -type f -newer "${R_FILE}" -print0
) |  rsync -av0RD --files-from=- "${S_LOC}" "./$today"


You can remove v (verbose) from the rsync options above once you are happy it is working as intended.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to add a date column (today's date) in file

Hi I have file with number status and date1 and date1 field, want add a column today between column date1 and date2. file1.txt number status date1 date2 ===== ==== === ===== 34567 open 27/06/13 28/06/13 45678 open 27/06/13 28/06/13 43567 open 27/06/13 28/06/13 ... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

2. Shell Programming and Scripting

UNIX date fuction - how to deduct days from today's date

Hi, One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is... (4 Replies)
Discussion started by: juzz4fun
4 Replies

3. Shell Programming and Scripting

[Solved] Replace yesterday date with today's date except from the first line

Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use... (3 Replies)
Discussion started by: Lilu_CK
3 Replies

4. UNIX for Dummies Questions & Answers

date command option e Help needed please!!

Hi All, I was trying to get the date in format "Feb2" I tried option "e" giving me a padded space and getting the result as "Feb 2". Though its working fine for dates 10 to 31. Please suggest me how to get rid of this space before date. Thanks Olivia (4 Replies)
Discussion started by: Olivia
4 Replies

5. Shell Programming and Scripting

rsync backup mode(--backup) Are there any options to remove backup folders on successful deployment?

Hi Everyone, we are running rsync with --backup mode, Are there any rsync options to remove backup folders on successful deployment? Thanks in adv. (0 Replies)
Discussion started by: MVEERA
0 Replies

6. Shell Programming and Scripting

how to use WGET command to get today's date?

I need to get the current date off a remote site, such as Google or Yahoo. Does anyone know how to use the wget command on a Solaris 10 system to do this? I recall a long time ago, where using "wget" will get a bunch of info off a site, and then, you can extract the date from all of that info. ... (6 Replies)
Discussion started by: newbie09
6 Replies

7. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

8. HP-UX

Backup Script using fbackup command Help Needed.

Hi Friends, I'm new to unix, I have the below script which takes regular backup. Now if fbackup fails I get the below messages in my log as fbackup(3047): could not open output file /dev/rmt/0m fbackup(3019): would you like to enter a new output file? fbackup(3004): writer aborting... (4 Replies)
Discussion started by: avik.nandi
4 Replies

9. Shell Programming and Scripting

Backup of today's file

Hiii, Here is the part o fmy script- for file in $FileList do if ]; then echo "Skips $file file. It is todays file" if ];then cp $file $BackupLocation 2>/dev/null ... (3 Replies)
Discussion started by: namishtiwari
3 Replies

10. Shell Programming and Scripting

Help needed on Date command

Hi, I am facing one problem with date command.Actually I want to use this command to get the last month,not the current month..OK,I can do current month - 1 and give special condition for january,But this time i need last month as strings like January,februaury,march etc... There is option... (5 Replies)
Discussion started by: nikunj
5 Replies
Login or Register to Ask a Question