0

I cant use cp -p because it also copies the user which I don't want and --preserve doesn't work because AIX apparently doesn't support that option? I get an error. Anyways, I just want to do the following:

cp /folder/file/* /newfolder/file/*

Then use touch -r on each file to copy the modified/access time.

I am terrible with scripting so any help is appreciated.

1
  • "I just want to do the following: cp /folder/file/* /newfolder/file/*" – Oh, I think you don't, especially if /newfolder/file/ is not empty. See this answer. May 14 '19 at 15:28
0

While I'm not familiar with AIX, it seems to support rsync, https://www.ibm.com/developerworks/aix/library/au-rsyncfamily/index.html. So no need to re-invent the wheel, use rsync with the -t option to preserve modified times. See the page https://linux.die.net/man/1/rsync

Note that I would avoid using the -a archive option as that includes too many attributes that it copies for you. So you might use something like rsync -rltvx /folder/file /newfolder

If you're thinking of using this as a backup solution, then you will want to consider what you want to happen with files that are deleted on the source side on purpose, vs ones that were deleted by accident. By default rsync does not delete any files in either source or destination. You can instruct it to delete files in the destination that do not exist in the source, creating a mirror of the source. However if this is your only copy of your data, you won't be protected against accidental deletions. There is also the problem of if a source file becomes corrupt somehow this can mirror to the copy before you realise, and you're in trouble again.

While I've seen (but never used) some posts, such as this, on using rsync to create a system of hard links to make a deduplicated backup repository of multiple 'snapshots' of your data, I personally enjoy the benefits of a more feature rich backup solution such as Borg Backup

5
  • Its a good thing I had a backup of the files already because apparently rsync moves the files? I tried that command and then deleted the files from my test folder only to find the originals were then gone. May 14 '19 at 16:51
  • @LeperMessiah that's unusual that it would move the files, you should check the help available from your rsync install to see what options it has and what its defaults are. rsync is normally a copy only tool. It does have some options to delete extra files in the destination that are not in the source, but they are not the defaults. May 15 '19 at 1:15
  • Well I must have been checked out or half asleep. I think I was in the wrong folder when I deleted the files. Anyways the rsync works like a charm now. May 15 '19 at 15:52
  • My only question now is this. To restore the files ONLY if the ones I backed up are newer than the ones in the original directory, do I use rsync -uv /backupfolder /originalfolder? May 15 '19 at 15:58
  • @LeperMessiah yes the -u option will update only files that are newer like you are imagining. However there are a few potential issues, 1) you will need to ensure the originalFolder does not have an existing file with a newer timestamp than the one you want to restore, and doing a full rsync may include files that were deleted on purpose, or make extra copies of files that were moved or renamed. May 16 '19 at 3:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.