Results 1 to 9 of 9
Oftentimes, I want to restore a directory from a tar.gz backup file.
When I extract the backup tar.gz, is there a way to make it only replace newer files in ...
- 01-29-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 8
replace newer files when extracting from tar
Oftentimes, I want to restore a directory from a tar.gz backup file.
When I extract the backup tar.gz, is there a way to make it only replace newer files in the target directory?
Currently, I have only been able to achieve this by deleting the entire target directory and extracting the entire backup file. This is time consuming because the backups are sometimes hundreds of gigabytes.
Thanks in advance.
- 01-29-2011 #2
From the man page for tar:
-k, --keep-old-files
don't replace existing files when extracting
- 01-29-2011 #3Just Joined!
- Join Date
- Jan 2011
- Posts
- 8
so, i don't think this actually works as it simply wouldn't overwrite any of the files in the directory i am trying to restore to an earlier state.
- 01-29-2011 #4
Try this, also from the man page, which you might want to read:
--keep-newer-files
don't replace existing files that are newer than their archive copies
- 01-29-2011 #5
I think the OP is looking for
Code:--overwrite overwrite existing files and directory metadata when extracting
- 01-29-2011 #6
That wasn't what I understood the question to be, but maybe...
- 01-29-2011 #7Just Joined!
- Join Date
- Jan 2011
- Posts
- 8
no, this doesn't work either because the newer files are the ones i want to replace.
--overwrite will accomplish my end goal, but it is no faster than deleting the directory and re-extracting it.
the issue is that since the last backup, maybe only 10-20 files out of 20 million were modified. it is inefficient to have to overwrite 20 million files when really only 10-20 need to be restored to their previous state. does anybody know of a way that this can be accomplished in a more efficient manner?
- 01-29-2011 #8
I think the way to approach this is to delete the newer files, and that can be done based on the date, and then run either tar or better, rsync, and have it ignore existing files. That way only files that don't exist, because you just deleted them, will be copied.
Are you sure you're going the correct direction with this tar? I've never seen a need to replace modified files with older ones, but if that's what you really need to do, the only way I know to do that is to delete the newer files first, and then transfer only missing files. If you don't need compression, I think rsync is a better tool for this. You could easily make up a script that would delete files newer than the original backup, then rsync only missing files. That shouldn't take long.
Find is probably the tool you want to do the deletions. Read the man page for find, and Delete Files In Directory By Date - Linux / UNIX Forum and Delete Files Older Than x Days on Linux - How-To Geek. Mtime may be better than ctime, depending on what is happening to the files you want to delete. Use -10 instead of +10 (or whatever number) to find newer files instead of older ones. Finding the required number is left as an exercise for the reader.
Last edited by sgosnell; 01-29-2011 at 08:03 PM.
- 01-30-2011 #9


Reply With Quote
