Jump to content

Archived

This topic is now archived and is closed to further replies.

infernon

looking for guidance on an assignment

Recommended Posts

Hello Everyone,

I am completely new to PHP.  Other than doing some basic stuff with MySQL databases and getting familiar with the fundamentals, I don't know much more than that.

I have recently been assigned a challenge from a friend.  He uses something called DirectAdmin to perform nightly backups.  He wants to tell DirectAdmin to perform a nightly backup, but to have it cron a script afterwards that looks at the directories in the backup directory (they're all stored in one directory) takes everything other than the two newest backups (backup directories are named with a date) and deletes them.  If the directory doesn't match the date format of the other directories, he wants the script to skip it.  If there is a problem with the script running, he wants to have it e-mail someone with the reason that it failed.

Now, given my limited knowledge of PHP and my zero-knowledge of the Linux command line (I should have mentioned that this is on a Linux box), what exactly should I learn that would get me to my goal the fastest.  I'm not looking for someone to write the script for me, obviously, but I don't know which topics I should be focusing on.  Also, if anyone knows of a great tutorial (I didn't really see anything in the tutorials section of this site), that would be great too.

Share this post


Link to post
Share on other sites
Ask someone with limited knowledge of php ... to create a script that will automatically delete files, etc. Sounds like a friend with a death wish to me.

The readdir() and unlink() functions are good starting points in the online manual.  Check the user notes on these pages for examples:

http://ca.php.net/manual/en/function.readdir.php
http://ca.php.net/manual/en/function.unlink.php

Share this post


Link to post
Share on other sites
[quote]Ask someone with limited knowledge of php ... to create a script that will automatically delete files, etc. Sounds like a friend with a death wish to me.[/quote]
Agreed

Try looking at the mail() function which will send an email. The filetime() function returns a UNIX timestamp of when it was last modified. This can be used with the date() function to make it readable and comparable to other dates.

This is the example from the PHP site:
[code]<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (file_exists($filename)) {
  echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?> [/code]

The unlink() function deletes files.

I think those functions you should look at first.

Cron is quite simple. If you just set cron to run the PHP file after the backup. Try searching google for the commands I think it is php- although don't quote me on that one.

Hope that helps,
Cold

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.