Solved

back-up files

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If 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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 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