An important process for any company is to make back up of it's data. This helps during the debugging process of programs that make use or create the data. The following code will take in 4 parameters, create a back up of the file by adding a date time extension to it and scans the back up folder for any files that are older than a specified number of days and deletes them
#!/bin/ksh
fileName=$1
filePath=$2
backupDir=$3
olderThan=$4
datetime=date +"%C%y%m%d_%H%M%S"
cp $filePath"/"$fileName $backupDir"/"$fileName_$datetime
find $backupDir"/"$fileName* -mtime +7 -exec rm -f {} \;
The first parameter will be the file you want to create a backup of. The second parameter the path to that file, the third parameter is the path to the backup directory and the fourth paramet is the number of days you want the file to be kept for before it is deleted. I saved the file as mkbkp.sh and called it in my program like this
fileName=testFile.php fileDirectory=/tmp backupDir=/backup/folder numOfDays=60 [program code] mkbkp.sh $fileName $fileDirectory $backupDir $numOfDays