Solved

back-up files

Posted on 2003-12-03
5
251 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now