Jump to content

looking for guidance on an assignment


infernon

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.

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.