File Backup - TAR help

Hi,

Another rookie here.

I have a script I am developing to backup files from various directories onto a windows machine.

Script description:

  • mv files from various directories
  • tar all files in that directory
  • export to windows server for safe keeping, external backups.

The part I am stuck with is how TAR can determine which files in the directories are older than 2 days, then how to move them into a different directory which I can TAR then export.

I have been trying to use the find command as follows but I am inexperienced and haven't found google to be helpful yet.

find $BACKUPDIR1/* -mtime +2 -exec tar zcvf {}.tgz 

Any thoughts?

If you are trying to create separate tar files then try the following,

find ./t/* -mmin -10 -exec tar zcvf {}.tgz {} \;

first argument to find is path, you dont have to give * anyway.

I think its the way you are naming your filename. "The filename can include wildcard characters (*,?, and []) but these characters must be quoted."

Sobell,Mark. A Practical Gude to Linux Commands, Eitors, and Shell Programming. 2010. page 690.

appreciate the help, quick thought as I have realised I am doing something wrong.

Can I pass the results of find into the mv command in the same way I was hoping to do with the tar

Then i only need to TAR 1 file, and that filename won't changed (well add timestampt but thats easy).

something like:

find "all files in these directories" -mtime +2 -exec mv {} /"tar directory"
tar zcvf "tar directory"

find /PATH -type f -mtime +2 -exec mv {} /TAR_directory \;
tar zcvf mcclunyboy.tar.gz /TAR_directory

I was almost there, just needed reassurance

We have a disk space issue on a db server I am hoping to use this to copy out backup files, it has to be better than just deleting them like we do at the minute.

I appreciate your help, my apologies for the missing code tags