Hi all,
Sorry if this is in the wrong place, I wasn't sure what category "tar" would come under. I have used tar before to backup an entire site in one go, just specifying to start in the route directory. But now I need to just backup a few different files from various places within the directory structure. So first of all I just want to check, it is possible to just add singular files to the archive file isn't it? Just by listing off the filenames instead of giving one directory?
Assuming I'm right about being able to do that, my other problem is that when I put these individual files into the archive, I need to put them into directories. So it may be in /this/handy/folder on the website, but needs to be in /this/backup/folder in my archive. So is it possible to state the filename to archive followerd by the folder to put it in when it's archived?
Or, if that's not possible, can I at least rename the files before they are put into the archive, but still preserving the names of the original files? So it's called myfile.php on the server, but mybackupFile.php in my archive.
If I can't do any of this then the only thing I can think of is to create the directories that I need, copy the files into those relevant directories, add the directories to the tar file, and then delete those copied files and new directories. Much more messy though, so any suggestions are welcome!
Thanks
Help using tar!
Moderator: General Moderators
It needs to be 'on the fly' unfortunately, so the user enters into a form what they want to back-up, and it simply returns a link on the next page to their nicely backed-up file!
The archive needs to contain extra information about the selections the user made for the backup. It's a bit long winded, but for example maybe I gave them a selection of fruit and they selected "apples" and "oranges" - in which case some of the files in their archive need to either have "apples_" added to the front of the filename, or need to be in a folder called "apples" and equally some need to either have "oranges_" added to the front of the filename, or need to be put in a folder called "oranges". But on the server, all of these files may be in a folder called /my/downloads/. Weird I know...
So if I was to use --append on a file in a certain folder on the server, would it preserve the folder it was in when it adds it to the archive file? And if that folder already exists in the archive, would it just add the file without deleting the rest of the existing content? And is there a way to rename it at the same time? If the answer to all those things is yes, that would be perfect!
The archive needs to contain extra information about the selections the user made for the backup. It's a bit long winded, but for example maybe I gave them a selection of fruit and they selected "apples" and "oranges" - in which case some of the files in their archive need to either have "apples_" added to the front of the filename, or need to be in a folder called "apples" and equally some need to either have "oranges_" added to the front of the filename, or need to be put in a folder called "oranges". But on the server, all of these files may be in a folder called /my/downloads/. Weird I know...
So if I was to use --append on a file in a certain folder on the server, would it preserve the folder it was in when it adds it to the archive file? And if that folder already exists in the archive, would it just add the file without deleting the rest of the existing content? And is there a way to rename it at the same time? If the answer to all those things is yes, that would be perfect!
Thanks for everyones advice! If anyone else ever needs to do something similar, I found the best option was to not use tar at all! There doesn't seem to be a way of renaming things with tar which was a big draw back. In the end I found a class in Zend for creating Zip files which allows you to create folders within a zip file and add data with any name to those folders. Exactly what I needed! It's at http://www.zend.com/codex.php?id=696&single=1