Arbitrary tweets made by TheGingerDog (i.e. David Goodwin) up to 31 May 2011
Continue reading “Automated twitter compilation up to 31 May 2011”
Linux, PHP, geeky stuff … boring man.
Arbitrary tweets made by TheGingerDog (i.e. David Goodwin) up to 31 May 2011
Continue reading “Automated twitter compilation up to 31 May 2011”
I think I’m back into my running ‘habit’ again, after finally overcoming an achilles tendon and so on.
I randomly installed RunKeeper on my iPhone, and I seem to be running at about 4minutes 30seconds per kilometer (I did 9.6km at this pace). The furthest I’ve been recently is about 13-14 miles, I think…
So, upcoming events:
I had intended to do the Sherwood Marathon last year, but then I injured myself… so hopefully this year will work out better.
Arbitrary tweets made by TheGingerDog (i.e. David Goodwin) up to 25 May 2011
Continue reading “Automated twitter compilation up to 25 May 2011”
Perhaps the following will be of use to others. In a nutshell, it’s a python script which backs up a provided list of PostgreSQL databases. I’ve written it for Windows, but it should work on Linux too (just change the paths in the BACKUP_DIR and dumper variables. No doubt it could be changed to query PostgreSQL for a list of databases, and dump these individually (like the MySQL python dumping script I wrote some time ago), but for now… let’s just stick with something simple.
#!python
from time import gmtime, strftime
import subprocess
import os
import glob
import time
# change these as appropriate for your platform/environment :
USER = "postgres"
PASS = "postgres"
HOST = "localhost"
BACKUP_DIR = "e:\\postgresql_backups\\"
dumper = """ "c:\\program files\\postgresql\\8.1\\bin\\pg_dump" -U %s -Z 9 -f %s -F c %s """
def log(string):
print time.strftime("%Y-%m-%d-%H-%M-%S", time.gmtime()) + ": " + str(string)
# Change the value in brackets to keep more/fewer files. time.time() returns seconds since 1970...
# currently set to 2 days ago from when this script starts to run.
x_days_ago = time.time() - ( 60 * 60 * 24 * 2 )
os.putenv('PGPASSWORD', PASS)
database_list = subprocess.Popen('echo "select datname from pg_database" | psql -t -U %s -h %s template1' % (USER,HOST) , shell=True, stdout=subprocess.PIPE).stdout.readlines()
# Delete old backup files first.
for database_name in database_list :
database_name = database_name.strip()
if database_name == '':
continue
glob_list = glob.glob(BACKUP_DIR + database_name + '*' + '.pgdump')
for file in glob_list:
file_info = os.stat(file)
if file_info.st_ctime < x_days_ago:
log("Unlink: %s" % file)
os.unlink(file)
else:
log("Keeping : %s" % file)
log("Backup files older than %s deleted." % time.strftime('%c', time.gmtime(x_days_ago)))
# Now perform the backup.
for database_name in database_list :
log("dump started for %s" % database_name)
thetime = str(strftime("%Y-%m-%d-%H-%M"))
file_name = database_name + '_' + thetime + ".sql.pgdump"
#Run the pg_dump command to the right directory
command = dumper % (USER, BACKUP_DIR + file_name, database_name)
log(command)
subprocess.call(command,shell = True)
log("%s dump finished" % database_name)
log("Backup job complete.")
That’s all folks.
Dogboarding from DANIELS on Vimeo.
Want to see what changes you’re about to apply when doing a ‘yum update’ ? Similar-ish to how ‘apt-listchanges’ works…
On CentOS 5.6, try :
Note, python-dateutil seems to be an unmarked dependency – i.e. you get an error message like : “Dateutil module not available, so can’t parse dates” when trying to run ‘yum changelog all updates’.
Note, /etc/yum/pluginconf.d/changelog.conf (but this didn’t seem to need changing to me).
Now you can do :
shopt -s histappend shopt -s checkwinsize export HISTCONTROL=ignoredups:ignorespace export HISTTIMEFORMAT='%Y-%m-%d %H:%M:%S ' export EDITOR=vim
histappend: don’t overwrite .bash_history files on each logout; then when someone logs into the server, and messes something up, there’s a vague chance you’ll see what they did. Your history file will obviously grow to be quite big – but suppression of duplicates helps. Mine’s only 900kb after 7 months.
checkwinsize: check the window size after each command, might help some braindead programs cope with you resizing their windows, I guess.
HISTCONTROL: suppress duplicates, ignore spaces
HISTTIMEFORMAT: record a timestamp against each history entry; run ‘history’ to see an example of it’s output…
EDITOR: why would you not use vim?
SQL="select concat(TABLE_SCHEMA, '.', TABLE_NAME) from
information_schema.TABLES where TABLE_SCHEMA IN
('database1','database2', 'databaseN') and Data_free > 500
AND Engine = 'MyISAM' "
for table in $(mysql --skip-column-names --batch -u root -prahrah -e "$SQL")
do
mysql --batch -u root -pxxxxx -e "optimize table $table"
sleep 10
done
See also PHP Conference InnoDB talk and MySQL Tuner
I migrated a Magento instance from one host to another, and in the process earnt myself some free beer; everything went well, apart from some of the thumbnail images not appearing. The image URLs would look like :
/media/catalog/product/cache/1/image/5e06319eda06f020e43594a9c230972d/images/catalog/product/placeholder/image.jpg
Things tried which didn’t help :
I already knew the original host didn’t have a case sensitive file system, and this was partially fixed this using mod_speling in Apache, but this obviously doesn’t help when e.g. PHP decides to read and resize an image file.
I then tried comparing the contents in media/catalog/product with what’s in the catalog_product_entity_varchar table. So, in my case :
select value from catalog_product_entity_varchar where value like '/F%' limit 1;
returned something like :
/f/i/file_4_1.jpg
And looking in the above mentioned directory, only showed a directory called F. Simple fix… :
mv F f
(Obviously check the table doesn’t make reference to images with /F in them…. in my case it didn’t.)
<<reload web browser; images all appear and everything works.>>
What sort of idiot created case insensitive filesystems… grr.
Still, at least people can now browse online for Kitchens …. and see the appropriate thumbnails.
I’ve a few kvm guest servers, which I’ve been accessing using vnc – but this is a bit of a pain (getting port forwarding setup etc). Host and guests run Debian Squeeze with Grub2 installed/in use.
So, here’s how to do the ‘virsh console ‘ thing …
GRUB_TERMINAL=console GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200 --word=8 --parity=no --stop=1" GRUB_CMDLINE_LINUX_DEFAULT="" GRUB_CMDLINE_LINUX="text console=tty0 console=ttyS0,115200n8"
The libvirt config files I have already have the appropriate bits in them –
<serial type='pty'><target port='0'/></serial> <console type='pty'><target type='serial' port='0'/></console>