Solved

back-up files

Posted on 2003-12-03
5
254 Views
Last Modified: 2006-11-17
Hi, I'm trying to figure out a way to run a back-up of a directory that has more directories and regular files in it. This is easy with the copy function, but what I can't figure out is how to do back-ups (copy) after the first, so new made files can be backed up without having to make multiple copies of the same original directory with a different name.

I found this at php.net that copies all files and directories.--------------------

  function my_copy($oldname, $newname)
  {
   if(is_file($oldname)){
     $perms = fileperms($oldname);
     return copy($oldname, $newname) && chmod($newname, $perms);
   }
   else if(is_dir($oldname)){
     my_dir_copy($oldname, $newname);
   }
   else{
     die("Cannot copy file: $oldname (it's neither a file nor a directory)");
   }
  }
     
  function my_dir_copy($oldname, $newname)
  {
   if(!is_dir($newname)){
     mkdir($newname);
   }
   $dir = opendir($oldname);
   while($file = readdir($dir)){
     if($file == "." || $file == ".."){
       continue;
     }
     my_copy("$oldname/$file", "$newname/$file");
   }
   closedir($dir);
  }
-----------------------
But I don't understand the function attribute, I'm used to saying something like:

if ($action=="this")
{
 run code here
}

Thanks
0
Comment
Question by:dsyn
  • 2
  • 2
5 Comments
 
LVL 1

Author Comment

by:dsyn
ID: 9868225
point increase
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9868346
I dont understand  your question very well...

Do you mean you dont understant the format of the if() statement?

If thats your question, the if() statement checks to see if the expression evaluates to true. If you use the == operator, it either returns a true of a false. If you use any other expression, for example a function, its return value is used by the if statement.

for example.. if(foo()) will check for the return value of foo().

If your question is something else, please explain and I'll try to help.
0
 
LVL 1

Author Comment

by:dsyn
ID: 9869782
I want to back up a directory and everything inside it into another directory. After the initial back-up I want to be able to add new files without having to back-up files that have already been backed up.

Thanks.
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9875081
I dont know about linux... but in windows, you can check for the 'archive' attribute. If its set, you need to back up the file and reset this attribute. If its not set, it means that the file is not modified.

Hope this helps
0
 
LVL 6

Accepted Solution

by:
aolXFT earned 350 total points
ID: 9877065
Hmmm,

This sounds kinda like rsync

Check the last modified time of the archive, using filemtime();

Go through the directory you want to back up using the directory functions.

Test each file using filemtime(), and if it is newer than the archive then back it up

otherwise skip on to the next file.

I would suggest you do this with a recursive algorithm.

PS by the word 'archive' I mean back up directory.
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question