LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-09-2015, 05:50 AM   #1
doole
LQ Newbie
 
Registered: Jan 2015
Posts: 5

Rep: Reputation: Disabled
Script for copyng files with timestamp preserved


Hello

I need a bash script wich will copy files from one location to another with saved folder structure and with timetamp preserved. Can anyone help me to do this? Ty!
 
Old 01-09-2015, 06:00 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
cp -a is a possibility
 
Old 01-09-2015, 11:06 AM   #3
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Doesn't rsync have an option for this also? Could be overkill for the purpose but, perhaps, worth looking at?
 
Old 01-09-2015, 12:32 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Code:
rsync -vaz <source> <destination>
preserves them for me.

rsync version 3.1.0
 
Old 01-09-2015, 12:52 PM   #5
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
You can use tar also.
 
Old 01-09-2015, 03:56 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
If you want to preserve just the timestamps and not the permission bits or extended attributes, you can use "cp --preserve=timestamps" I have an alias "cpt" for that.
 
Old 01-09-2015, 04:17 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by doole View Post
I need a bash script wich will copy files from one location to another
Source and Destination both Linux partitions?
 
Old 01-10-2015, 08:59 AM   #8
doole
LQ Newbie
 
Registered: Jan 2015
Posts: 5

Original Poster
Rep: Reputation: Disabled
Ty for replies. I need to copy backups from linux partiton to windwos ntfs partition every day but to have timestamp preserved and to save directory structure. And its need to be automated.
 
Old 01-10-2015, 09:40 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by doole View Post
Ty for replies. I need to copy backups from linux partiton to windwos ntfs partition every day but to have timestamp preserved and to save directory structure. And its need to be automated.
Please read the "Question Guidelines" link in my posting signature. We will be happy to HELP you with things, but we are NOT going to write your scripts for you. We understand what you WANT, but you have to show effort of your own. There are THOUSANDS of very easily found bash scripting guides that can get you going, and you've been given hints in this thread.

Post what you have written/done of your own, and tell us where you're stuck. And bear in mind that you have just now told us you're copying from Linux to Windows...there are SOME permissions you won't be able to preserve, since Windows knows nothing about them. One way to get around this is to use tar to create a file on Linux (which WILL preserve the attributes), then copy that file to Windows.
 
Old 01-10-2015, 10:44 AM   #10
doole
LQ Newbie
 
Registered: Jan 2015
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Please read the "Question Guidelines" link in my posting signature. We will be happy to HELP you with things, but we are NOT going to write your scripts for you. We understand what you WANT, but you have to show effort of your own. There are THOUSANDS of very easily found bash scripting guides that can get you going, and you've been given hints in this thread.

Post what you have written/done of your own, and tell us where you're stuck. And bear in mind that you have just now told us you're copying from Linux to Windows...there are SOME permissions you won't be able to preserve, since Windows knows nothing about them. One way to get around this is to use tar to create a file on Linux (which WILL preserve the attributes), then copy that file to Windows.
Sorry that i pissed u off it wasnt my purpose. So far ive mounted shared disk from windows in linux and gave right premissions to it. I can copy files and stuff and it works good. Im searching for a way to avoid the script. As i saw cp -pr copy files with timestamp preserved. Also rsync working fine with -av option. Why am i avoiding script - i dont know nothing about bash scripting. Ive started with some tutorials but its not going so good. So im trying to combine commands to copy already backuped files from /home/d/folder1 and /home/d/folder2 which are on linux hdd and to put it on external hdd wich is on win machine, for example in H:/folder3 with saved folder structure. If i found i way i can put that command in script and set it in crontab to work everyday. I know only how to run one command from script. And dont yell cuz im just a few days in linux world. And ty for helping me and again sorry that i pissed u off.
 
Old 01-10-2015, 10:51 AM   #11
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,623

Rep: Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964Reputation: 7964
Quote:
Originally Posted by doole View Post
Sorry that i pissed u off it wasnt my purpose.
You have not pissed anyone off...merely telling you the LQ Rules and guidelines. On that subject, please also see the LQ Rules regarding text-speak (and not using it).
Quote:
So far ive mounted shared disk from windows in linux and gave right premissions to it. I can copy files and stuff and it works good. Im searching for a way to avoid the script. As i saw cp -pr copy files with timestamp preserved. Also rsync working fine with -av option. Why am i avoiding script - i dont know nothing about bash scripting. Ive started with some tutorials but its not going so good. So im trying to combine commands to copy already backuped files from /home/d/folder1 and /home/d/folder2 which are on linux hdd and to put it on external hdd wich is on win machine, for example in H:/folder3 with saved folder structure. If i found i way i can put that command in script and set it in crontab to work everyday. I know only how to run one command from script. And dont yell cuz im just a few days in linux world. And ty for helping me and again sorry that i pissed u off.
Again, no one is yelling, pissed etc. And until you actually START scripting, you will NEVER be any better at it than you are now. There is a link to bash scripting tutorial in my posting signature, and many thousands of others you can easily find. They all have examples and full explanations.

And a script is nothing BUT a list of "combined commands". If you know how to do this from the command-line now by typing things in, then congratulations...you've written your script. Put those lines in a file, make it executable (see the man page on the chmod command), and run it. You can either run it manually or by using cron to schedule it to run whenever you'd like. To schedule things, read the man page on the crontab command.
 
  


Reply



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
script to timestamp files with timestamp from directory eRJe Programming 4 11-13-2013 06:52 PM
[SOLVED] timestamp in files to 1901? xeon123 Linux - Newbie 3 11-03-2012 07:00 PM
[SOLVED] Need help sorting large number of files by timestamp and then greping those files scottjn Linux - Newbie 4 01-14-2011 10:42 AM
Low speed copyng and moving files Linux_coder Linux - General 1 04-11-2009 05:10 AM
script to sort files according to timestamp aeby Linux - Newbie 1 05-16-2007 08:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:13 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
Open Source Consulting | Domain Registration