Posts Tagged script

Daily PostgreSQL Backups script

Posted by on Wednesday, 23 June, 2010

I love Backups!
This one is for a daily dump of the database, rolling over every 10 days

Put the following into a file in /etc/cron.daily/postgres-backup

LIST=$(su - postgres -c "/usr/bin/psql -lt" |/usr/bin/awk '{ print $1}' |/bin/grep -vE '^-|:|^List|^Name|template[0|1]')
DATE=$(/bin/date '+%Y%m%d');
TENDAY=$(/bin/date -d'10 days ago' '+%Y%m%d');
/bin/mkdir -p $DIR/$DATE/
/bin/chown postgres:postgres $DIR/$DATE/
for d in $LIST
su - postgres -c "/usr/bin/pg_dump $d | gzip -c > $DIR/$DATE/$d.sql.gz"
rm -rf $DIR/$TENDAY/
/usr/bin/lftp -u "$FTPUSR,$FTPPASS" ${FTPHOST} -e "set ftp:ssl-protect-data true;mirror --reverse --delete $DIR/ /; exit"

WordPress & WordPress MU mass upgrade script 3.0

Posted by on Wednesday, 23 June, 2010

Sorry for the slower than usual update this time. I was rather busy/sidetracked and left it for a day or two before doing it. Since it wasn’t a exploit fix release i figured it wasn’t a major.

Anyway, here goes the new wordpress mass upgrade script. I no longer have a wordpress MU available to test on, it should technically work, but let me know if there are any problems at all with it.

This script will search /var/www (changeable in a variable) for any wordpress install and make sure its upgraded to the latest version. It pays to check each site after the upgrade to make sure plugins all worked (and upgrade plugins before the upgrade works also!). This version has a database change so i have forced the $sitename/upgrade.php call with a wget to save you some time. This occasionally fails, for no reason i can find, so it pays to check this.

Let me know if you have any bugs at all, or any problems.

Here’s your script to upgrade them all.


Next time I may endeavour to see if i can script putting sites into maintaince mode, disable plugins, upgrade etc 🙂

Easy Linux Firewalling using IPTables

Posted by on Sunday, 21 March, 2010

A lot of our customers have asked for firewalls, and since this is a common theme, i decided that I would help them out. Of course it can be a mission to learn how to make your own and what to do or not do, and some of the pre-made ones can be confusing.

So i decided to simplify it a little for you all by writing a firewall script. I originally took a script made by somebody else, then totally modified it to suit myself, then modified it again to suit any machine. You *should* be able to literally drop this in place on any server and have it *just work*.

All you need to do is edit the top couple of lines to set what ports you want open or closed. edit the other options (ie ssh port etc). Full instructions as follows

nano firewall # ctrl+x to exit when finished editing
chmod +x firewall

If you are still able to connect to your VPS in all the usual ways then you can add that into your init scripts. To check what ports you have open and want the outside world to connect to you can use

netstat -pant |grep LISTEN

If you are unable to login then you may need to log into the console of your VPS at

Adding it into the init scripts

cp firewall /etc/init.d/firewall

Debian Based (debian.ubuntu etc)

update-rc.d firewall defaults

Centos/RPM based

chkconfig --add firewall