The best way is to have a dev server and a production server. I don't
have that luxary either, so here is what I do. I keep separate
databases and keep separate include directories. I also have two
scripts that help with all of this. The first one is the one I use to
backup my Mysql databases, and I also use it to restore them to test
databases. I simply prepend test_ to all of my databases. That script
is called mysql_backup.pl and is below. The second script is one I use
to move files from my test environment to production environment.
I set up a cron job to run mysql_backup.pl every night. golive.pl is a
script I use to move a file to production as I finish testing it. I
call it like this:
golive index.php (This is for one file)
or
golive * (This is for an entire directory)
#!/usr/bin/perl
$now = time;
$directory = "/home/backups";
@databases = ("mysql", "database1", "database2");
foreach $database (@databases) {
$backup = "mysqldump \-\-add-drop-table -u user -ppassword
$database";
$zip = "| gzip > $directory/$database.$now.gz";
system("$backup $zip");
# This stays commented, because I don't want to restore all the time.
# unless($database eq "mysql") {
# $restore = "|mysql -u user -ppassword test_$database";
# system("$backup $restore");
# }
}
#!/usr/bin/perl
# Figure out where we are running this from
chomp ($path = `pwd`);
# Create a new path to where we are going to copy to
$newpath = $path;
$newpath =~ s/test_site/www/;
$newpath =~ s/test_phpdocs/phpdocs/;
# Set lastFile equal to empty string to initialize it
$lastFile = '';
# Loop through all of the input one line at a time
while(<>){
unless($ARGV eq 'univ_master.php') {
if($lastFile ne $ARGV) {
if($lastFile ne "") {
close TMP;
`cp $oldfile $newfile`;
`chgrp www-data $newfile`;
`chmod 660 $newfile`;
unlink ($oldfile);
print "$lastFile now live\n";
}
$lastFile = $ARGV;
open TMP, ">$path/$ARGV.tmp";
$oldfile = "$path/$ARGV.tmp";
$newfile = "$newpath/$ARGV";
}
s/test_site/www/g;
s/test_phpdocs/phpdocs/g;
s/test_nwdata/nwdata/g;
s/test_user_accounts/user_accounts/g;
print TMP;
}
}
unless($ARGV eq 'univ_master.php') {
close TMP;
$oldfile = "$path/$lastFile.tmp";
$newfile = "$newpath/$lastFile";
`cp $oldfile $newfile`;
`chgrp www-data $newfile`;
`chmod 660 $newfile`;
unlink ($oldfile);
print "$lastFile now live\n";
}
>
> Alternatively, how do you ensure that testing/playing/dev work doesn't
> foul production data?
>
> Enquiring minds... =dn
>
> PS my personal dev env is NTWusS 4.0, PHP4, MySQL, and Apache
--
Jason Stechschulte
jps...@unoh.edu
--
If you want to see useful Perl examples, we can certainly arrange to have
comp.lang.misc flooded with them, but I don't think that would help the
advance of civilization. :-)
-- Larry Wall in <1992Mar5.1...@netlabs.com>