Solved

back-up files

Posted on 2003-12-03
5
250 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
Comment Utility
point increase
0
 
LVL 3

Expert Comment

by:ashoooo
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 25
selecting a category and selecting subcategories 7 31
Not needed 13 53
Filter wordpress query 3 8
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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

771 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

10 Experts available now in Live!

Get 1:1 Help Now