|
Tech Notes -
General
|
|
Written by Rick
|
|
Wednesday, 03 March 2010 00:00 |
|
It's not uncommon to run across a need to duplicate a database for testing purposes. PostgreSQL provides for the ability to duplicate the structure and data content with a single command;
CREATE DATABASE newdb WITH TEMPLATE originaldb;
With any luck it's obvious one needs to replace "newdb" with the new database name and "originaldb" with the name of the source database.
I've executed this command in phpPgAdmin (v4.2-beta-1) with success on a 657MB database. The process took approximately 10 minutes. I have no doubt the command can be executed from the pgsql prompt as well.
PostgreSQL DB Server version 8.1.11.
|
|
|
Development -
PHP
|
|
Written by Rick
|
|
Monday, 25 January 2010 12:00 |
|
Creating a recordset and displaying data from a PostgreSQL table using PHP;
Making the connection:
$DB_HOST="hostname"; $DB_NAME="databasename"; $DB_USER="username"; $DB_PASSWORD="password";
$psql="Select DISTINCT fieldname FROM table"; $const = "host=".$DB_HOST." dbname=".$DB_NAME." user=".$DB_USER." password=".$DB_PASSWORD.""; $pcon=pg_connect($const); if (!$pcon) { echo "<script type=\"text/javascript\">alert(\"Unable to connect to PostgreSQL Server!\")</script><script type=\"text/javascript\">history.back()</script>"; }else{ $getRS = pg_exec($pcon,$psql); }
pg_close($pcon);
Create the recordset and display:
$getRS = psqlSelectRS($psql); $rows=pg_num_rows($getRS);
for ($i=0; $i<$rows; $i++) { $row_getRS=pg_fetch_row($getRS, $i); echo "Row Value: ".$row_getRS[0]."<br />; }
pg_free_result($getRS);
|
|
Tech Notes -
Linux
|
|
Written by Rick
|
|
Tuesday, 29 December 2009 11:33 |
|
An annoying little thing. When connecting via SSH to another machine for the first time SSH always prompts;
--- The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established. RSA key fingerprint is .............. Are you sure you want to continue connecting (yes/no)? ---
Typing "yes' each time can be pain in the butt. There is a way to change that behavior but, some believe it exposes you to a Man-in-the-middle attack.You've been advised!
I've changed settings in most of my /etc/ssh/ssh_config files to stop the machine from begging for a "yes" response, to just automatically adding the new host to the known_hosts file. I did that by changing the parameter value of StrictHostKeyChecking to "no" and restarting the SSH service.
Note: This does not stop SSH from checking that the host exists in the known_hosts file. It simply adds new hosts to the file without prompting.
|
|
Tech Notes -
Linux
|
|
Written by Rick
|
|
Wednesday, 23 December 2009 17:01 |
|
Here's a handy script to run rsync from the command-line that prompts for source and destination paths;
#! /usr/bin/php
<?php ## Control CLI parameters if (($argv[1]=="") OR ($argv[2]=="")) { echo "Options not specified.\r\n"; echo "Program Usage: "; echo $argv[0]." <i.e.: /source/path> <i.e.: /destination/path>\r\n\r\n"; exit; }else{ $srcpath=$argv[1]; $dstpath=$argv[2]; }
$starttime=date('G:i:s', strtotime('now'));
echo "Starting rsync...\r\n"; $retval=system("sudo rsync -avrl --delete ".$srcpath." ".$dstpath, $retval); if (!$retval==false) { echo "Backup from ".$srcpath." to ".$dstpath." is complete!\r\n\r\n"; }else{ echo "Backup from ".$srcpath." to ".$dstpath." FAILED!\r\n\r\n"; }
$endtime=date('G:i:s',strtotime('now'));
echo "\r\nStart time - ".$starttime."\r\n"; echo "End time - ".$endtime."\r\n\r\n"; echo "Script complete!\r\n";
?>
Note:
- The sudo command in the system call allows the script to be used to sync root user files. This can be removed if that behavior is not desired.
- The script also utilizes the --delete feature of rsync to remove files in the destination that do not exist in the source. Evaluate that behavior for your application as well.
|
|
Development -
PHP
|
|
Written by Rick
|
|
Tuesday, 10 November 2009 18:00 |
|
Administrators are often called upon to write scripts to accomplish tasks. I've been playing a lot with php cli scripting lately and had a need to create a script to startup a VirtualBox VM from the command line. Here's what it looks like;
#!/usr/bin/php <?php if ($argv[1]=="") { echo "Options not specified.\n\r"; echo "Usage: "; echo $argv[0]." <vmname>\n\r\n\r"; exit; }else{ $vm=$argv[1]; system("VBoxManage vmstatistics ". $vm,$retval); if ($retval==1) { echo "Starting Virtual Machine ".$vm."\r\n"; #system("VBoxVRDP -startvm ".$vm,$rval); system("VBoxManage startvm ".$vm." --type headless",$rval); }else{ echo $vm." appears to be running already!\r\n"; exit; } } ?>
I found using VboxVRDP and VBoxHeadless left the script incomplete and open even after shutting down the virtual machine. I've left a commented line with the VBoxVRDP startup statement for your testing purposes.
|
|
|
<< Start < Prev 1 2 3 Next > End >>
|
|
Page 1 of 3 |