infernon Posted October 14, 2006 Share Posted October 14, 2006 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 14, 2006 Share Posted October 14, 2006 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.phphttp://ca.php.net/manual/en/function.unlink.php Quote Link to comment Share on other sites More sharing options...
coldkill Posted October 14, 2006 Share Posted October 14, 2006 [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]AgreedTry 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 Quote Link to comment Share on other sites More sharing options...
infernon Posted October 14, 2006 Author Share Posted October 14, 2006 This is awesome. Thanks guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.