Solved

back-up files

Posted on 2003-12-03
5
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

734 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