Archive for the 'linux' Category

backup linux server with backupninja

want to backup your linux server? looked at a few solu­tions. been using rsync running daily via a cron job which worked well
made a script (called sys_backup) that looks like this…
first do a ‘touch sys_backup’ on the command line without the quotes (in fact that applies through­out this page…open it with your favour­ite text editor and paste the fol­low­ing in (repla­cing /media/backup/local with the path to your backup directory).

#!/bin/bash
rsync –avp –delete /var /media/backup/local
rsync –avp –delete /etc /media/backup/local
rsync –avp — delete /home /media/backup/local

to run the script become root (as you’ll need that per­mis­sion for /var and /etc) and run ‘./sys_backup’ without the quotes.
however, i wanted some­thing a bit more com­pre­hens­ive (and incre­mental) without me putting in too much effort. looked at bacula. too com­plic­ated. settled on backupn­inja. to install on a debian based system, as root, issue the fol­low­ing ‘apt-get install backupn­inja’ to grab it from the repos. next we want to edit the main con­fig­ur­a­tion file. ‘joe /etc/backupninja.conf’ will open it and you can change the para­met­ers to suit your setup. mine’s only a local backup so it looks a bit like this.
#                          |\_
# B A C K U P N I N J A   /()/
#                         ‘\|
# main con­fig­ur­a­tion file
#

# how verbose to make the logs
# 5 — Debug­ging mes­sages     (and below)
# 4 — Inform­a­tional mes­sages (and below)
# 3 — Warn­ings               (and below)
# 2 — Errors                 (and below)
# 1 — Fatal errors           (only)
log­level = 4

# send a summary of the backup status to
# this email address:
reporte­m­ail = col@localhost

# if set to ‘yes’, a report email will be gen­er­ated
# even if all modules repor­ted success. (default = yes)
reportsuc­cess = yes

# if set to ‘yes’, info mes­sages from hand­lers will be
# sent into the email (default = no)
reportinfo = no

# if set to ‘yes’, a report email will be gen­er­ated
# even if there was no error. (default = yes)
report­warn­ing = yes

# if set to ‘yes’, disk space usage will be included in
# the backup email report
reportspace = yes

# where to rsync the backupninja.log to be aggreg­ated in
# a ninjare­port
reporthost =

# what user to connect to reporthost to sync the
# backupninja.log
reportuser = ninja

# where on the reporthost should the report go
# NOTE: the name of the log will be used in the report,
# use a glob­ally unique name, prefer­ably the host­name
report­dir­ect­ory = /var/lib/backupninja/reports

# set to the admin­is­tra­tion group that is allowed to
# read/write con­fig­ur­a­tion files in /etc/backup.d
admin­group = root

#######################################################
# for most install­a­tions, the defaults below are good #
#######################################################

# where to log:
logfile = /var/log/backupninja.log

# dir­ect­ory where all the backup con­fig­ur­a­tion files live
con­fig­dir­ect­ory = /etc/backup.d

# where backupn­inja helper scripts are found
script­dir­ect­ory = /usr/share/backupninja

# where backupn­inja libs are found
lib­dir­ect­ory = /usr/lib/backupninja

# whether to use colors in the log file
usecol­ors = yes

# default value for ‘when’
when = every­day at 01:00

# if running vserv­ers, set to yes
vserv­ers = no

# pro­grams paths
# SLAPCAT=/usr/sbin/slapcat
# LDAPSEARCH=/usr/bin/ldapsearch
# RDIFFBACKUP=/usr/bin/rdiff-backup
# CSTREAM=/usr/bin/cstream
# MYSQL=/usr/bin/mysql
# MYSQLHOTCOPY=/usr/bin/mysqlhotcopy
# MYSQLDUMP=/usr/bin/mysqldump
# PSQL=/usr/bin/psql
# PGSQLDUMP=/usr/bin/pg_dump
# PGSQLDUMPALL=/usr/bin/pg_dumpall
# GZIP=/bin/gzip
# GZIP_OPTS=’–rsyncable’
# RSYNC=/usr/bin/rsync
# VSERVERINFO=/usr/sbin/vserver-info
# VSERVER=/usr/sbin/vserver
# VROOTDIR=/var/lib/vservers

most of the set­tings have been left as they are. save the file with a ctrl+k+x in joe.
i’m using rdiff only but there are other options avail­able. see the backupn­inja wiki for more info.
now to get an action (or backup job) sorted. from the wiki above we’re going to use the action.rdiff file. first we want to cd into the backup.d dir­ect­ory like so. as root ‘cd /etc/backup.d’. then ‘wget http://cloudplasma.co.uk/wp-content/uploads/action.rdiff’ to down­load the default con­fig­ur­a­tion file. do a ‘joe action.rdiff’ to open it and tweak it to your liking. mine resembles the fol­low­ing…
######################################################
## source section
## (where the files to be backed up are coming from)

[source]

# an optional sub­dir­ect­ory below ‘dir­ect­ory’ (see [dest])
label = box

# only local type is cur­rently sup­por­ted
type = local

# how many days of data to keep
keep = 185

# files to include in the backup
# (sup­ports glob­bing with ‘*’)
include = /var/spool/cron/crontabs
include = /var/backups
include = /etc
include = /root
include = /home
include = /usr/local/bin
include = /usr/local/sbin
include = /var/lib/dpkg/status
include = /var/lib/dpkg/status-old

# files to exclude from the backup
# (sup­ports glob­bing with ‘*’)
#exclude = /home/*/.gnupg

######################################################
## des­tin­a­tion section
## (where the files are copied to)

[dest]

# remote or local? If local, you dont need to specify a host below
type = local

# the machine which will receive the backups
host = backup

# put the backups under this dir­ect­ory
dir­ect­ory = /media/backup/ninja

# make the files owned by this user
# note: you must be able to ssh backupuser@backhost
# without spe­cify­ing a pass­word
# user = col

save it with ctrl+k+x as before. now it should run at 1.00 am every day. you can try it now by running ‘backupn­ija –n’ as root.
if you run into per­mis­sion errors make sure that action.rdiff has 400 per­mis­sions (‘chmod 400 action.rdiff’) and that joe hasn’t left a temp version of action.rdiff in the backup dir­ect­ory (‘rm action.rdiff~’).

Post to Twitter

migrate to a new linux server

i’m upgrad­ing my home server. a faith­ful 1GHz PIII with 512MB has served(!) me well for 4 years but i though it was time to expand. got a rather nice box with a 1.6GHz pro­cessor (quad core atom d510), 4GB of RAM and a 500GB SATA disk (room for another 2 disks also).

the old machine runs debian 6.0.3 and deals with a few chores…apache, postfix, remote ssh tun­nel­ling, sub­sonic and a couple of samba shares. the old install is obvi­ously 32 bit…the new one will be 64 bit (also running debian 6.0.3…i haven’t found a more stable server os) so that pre­vents a straight rsync as many of the pack­ages will be incom­pat­ible with the dif­fer­ent archi­tec­ture. a chum got me thinking…a simple way to get a new box running the same apps as the old one is to rep­lic­ate the pack­ages that are installed. this can be done simply with the following…on the old box issue the fol­low­ing in a terminal…doesn’t need to be as root…

dpkg –get-selections > installedpackages

this creates a file called ‘installed­pack­ages’ that con­tains all the applic­a­tions that have been installed on the old system. if you have the new server up and running and access­ible via ssh you can then copy the file over with scp…if not use USB

scp installed­pack­ages username@newserver:/home/username

this will plonk it into your home folder on the new machine. so now log into your new machine and as root issue the command

dpkg –set-selections < installedpackages

and then

apt-get dselect-upgrade

this will install all the pack­ages that ran on the old box…to the new one.

NB that this, obvi­ously, doesn’t move your /home dir­ect­or­ies, email, web sites or any con­fig­ur­a­tion files. you can do this via USB or using the scp method detailed above. lots of the con­fig­ur­a­tion files are stored in /etc, web sites are gen­er­ally in /var/www. i’m not dealing with things like mysql now but here’s some info on that.

Post to Twitter

ubuntu 12.04 and xubuntu 12.04 — a wee look

as usual i like to have a mess about with ubuntu alpha ver­sions. this time it’s a look at ubuntu 12.04 (precise pangolin…again…fine work there people) an LTS release which means it’ll get support until april of 2017…that’s a while. get the daily iso from here and burn it to a dvd or whap it onto a usb stick using dd or unet­bootin. the install process still fea­tures a lot of the artwork from 11.10…unity is still in use…and looks much the same as it did previously…and that’s not, in this users opinion, a good thing. in fact if you follow this post down you’ll see that i quickly tire of ubuntu 12.04 and turned it into xubuntu 12.04…

doing the initial update using apt-get update and then apt-get dist-upgrade (as root). a couple of the ‘extra. repos­it­or­ies were unavail­able. also neither ai32-libs or ia32-libs-multiarch would install due to depend­ency problems.

this build of ubuntu is ship­ping with firefox 9 and thun­der­bird 9 but by the time april 2012 rolls around both of these will prob­ably have morphed to version 11 with no notice­able improvements.

as i said…they’re stick­ing with unity. just as feature-rich as always…

not too light on resources either but then i’ve got a bit of ram to spare.

now as i men­tioned before…unity isn’t for me. i could have installed gnome 3 but prefer things to be slightly more con­fig­ur­able so here’s how to add xfce as a desktop environment…in other words change ubuntu 12.04 into xubuntu 12.04…

as root issue the command apt-get install xubuntu-desktop this will grab 120MB or so from the repositories…after it has fin­ished log out. when you’re greeted with the log in screen click the wee gear icon next to your user­name and choose ‘xfce session’ or whatever. this’ll give you some­thing slightly more usable. i’ve used xfce a fair bit in the past…still not 100% sure of it but it kicks unity’s arse…see below for a quick look.

too many icons…not sure why all my drives have to be shown by default. right-click the bottom menu and go into panel options to make it auto-hide.

ah…proper menus…bliss…

and there’s my daily look at el reg…with some thumbnails…

to sum up. ubuntu’s going in the wrong dir­ec­tion for me interface-wise. they won’t change and i don’t think i’ll ever like it. for an alpha version it seems stable though…adding xfce makes it a lot nicer to use. how long will i stick with it? prob­ably until this afternoon.

Post to Twitter

subsonic media streamer

got a server at home? want to stream media over your home network or inter­net? linux (although other plat­forms are sup­por­ted)? yes? read on then.

sub­sonic should take care of all your media stream­ing desires. grab it from here. i’ll be using the debian version on my head­er­less server.

first off install the java runtime envir­on­ment (shame, that)…as root issue the following

apt-get install openjdk-6-jre

once that’s com­plete you’ll need to install the binary you down­loaded earlier. again, as root…

dpkg -i subsonic-x.x.deb

and that should be it up and running. login to the new install­a­tion using your domain or IP at port 4040 (i’m testing from home so for me that’s http://box:4040) and you should be greeted with some­thing like this

user­name and pass­word are admin (change the pass­word straight after you login for the first time). most import­ant step? add the path to your media…

a dir­ect­ory for your playl­ists isn’t created during the install pro­ced­ure so add one now…as root…

mkdir /var/playlists

now to forward the rel­ev­ant ports on your router so that stream­ing will work remotely…the default is, as men­tioned before, 4040 but you can change that if you like

if you want to stream from afar you’ll need a domain name if you don’t want to use your IP (which will change if you have a dynamic con­nec­tion). i use dyn.com but it seems their free service doesn’t exist anymore…i could be wrong. you could try no-ip.com.

that’s about it…you can now browse your media, load and save playlists…and play your tunes.

EDIT — i like it. a lot. have donated and i recom­mend you do too if you find it useful. it’ll give you a con­stant url for your dynamic IP address…android app that works after the 30 days trial…and help the developer to con­tinue to improve this crack­ing bit of code.

Post to Twitter


Bear