tip

You are currently browsing articles tagged tip.

VPS hosting is available, affordable, and just a little bit scary.  In order to alleviate some of risk that is taken when moving to a VPS that is not under our benevolent control, we need to set up a reliable data backup solution.  The setup that I incorporated involves a server in the cloud backing up to my box.com account.  To accomplish this on CentOS 6, you can just use the following commands in a script that is executed periodically:

 

#!/bin/bash
HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
echo “Files backup to cloud”
eval $(gpg-agent –daemon)
export SIGN_PASSPHRASE=””
export PASSPHRASE=””
export FTP_PASSWORD=”your password”
echo “Files backup to cloud”
duplicity –use-agent –encrypt-key YOUR_ENCRYPTION_KEY –full-if-older-than 4M /var/spool/duplicity/ webdavs://YOUR_BOX_COM_ACCOUNT@dav.box.com/dav/lynetSky/duplicity && duplicity –use-agent –encrypt-key YOUR_ENCRYPTION_KEY remove-all-but-n-full 4 –force webdavs://YOUR_BOX_COM_ACCOUNT@dav.box.com/dav/lynetSky/duplicity && duplicity –use-agent –encrypt-key YOUR_ENCRYPTION_KEY remove-all-inc-of-but-n-full 2 –force webdavs://YOUR_BOX_COM_ACCOUNT@dav.box.com/dav/lynetSky/duplicity
echo “Database backup to cloud”
duplicity –use-agent –encrypt-key YOUR_ENCRYPTION_KEY –full-if-older-than 4M /var/spool/holland/ webdavs://YOUR_BOX_COM_ACCOUNT@dav.box.com/dav/lynetSky/holland && duplicity –use-agent –encrypt-key YOUR_ENCRYPTION_KEY remove-all-but-n-full 4 –force webdavs://YOUR_BOX_COM_ACCOUNT@dav.box.com/dav/lynetSky/holland && duplicity –use-agent –encrypt-key YOUR_ENCRYPTION_KEY remove-all-inc-of-but-n-full 2 –force webdavs://YOUR_BOX_COM_ACCOUNT@dav.box.com/dav/lynetSky/holland

 

These commands will instruct duplicity to make a full backup every four months (–full-if-older-than 4M).  When this script runs in the in-between times (say 2 months after the last full backup), it will create an incremental backup.  Duplicity will keep four full backups.  This is specified by the remove-all-but-n-full 4 directive in the command.  Specifying remove-all-inc-of-but-n-full 1 tells duplicity to remove all incremental updates except in the case of the last two backup set.  A backup set includes the last full backup and its incremental backups.  Yes, this is a bit complicated.  Yes, it is worth it.

The end result is this: in sixteen months, there will be four full backups (a new full backup is created every four months).  The newest two of these will have the incremental backups as well as the full backups.  This way, file history will be completely preserved for the most recent eight month period.  If we are really desperate, we can recover a file that twelve months old or sixteen months old.

We need to consider what happens at month seventeen.  We will have four full backups, the oldest full backup will be seventeen months old.  We should not expect to be able to recover files that are over sixteen months old.  When we continue on to our twentieth month  the oldest full backup will be removed and we will be back to only having sixteen months of recoverable data.  Always think of your maximum time to recover a file as (–full-if-older-than 4M * remove-all-but-n-full 4 == 4 months * 4 full backups = 16 months of full backups).

Storing four full copies of the data on a backup is (most likely) overkill for what I am doing.  These options were added when I decided that a full backup on another server lacked one thing: files that were deleted on the server were never deleted in the backup location.  Then, of course, my mind wondered into using rsync instead of duplicity.  It’s true, if all we need is a single backup of the files, rsync can provide a better solution (I do this with my personal photos and videos at home).  However, the point in time snapshot duplicity provides can be used for forensics and change tracking.  This solution as scripted above isn’t one size fits all.  Use the tools and settings that work the best for you.

This setup absolutely saved this site and the other sites I run.  The SAN that this VPS (at the time of this writing) is running on became corrupted and all of the data would’ve been lost had I not used an external site for backups.  If you are someone who is worried about the security of your backups, remember that duplicity has an automatic encryption algorithm built in.  Security of your data is there, just make sure to backup your keys so you can read the files.

To conclude: backups can save you important information; the cloud is a great place to store your backups; duplicity is a great tool that can automate this process.

Tags: , ,

Printing is not an easy task.  It is easy to get tied into intricate details of environment specific configuration settings such as margins and paper size. Therefore, printing a PDF without a library is not recommended unless you have a lot of time or are really interested in that sort of thing.  There are two libraries that can perform this task already.   One will be exampled today, and another tomorrow.

Today’s library is PDFRenderer https://pdf-renderer.dev.java.net/.   This library was released by Sun a couple of years ago.   Note that this example does not map a FileChannel object as some examples do.  Using a FileChannel made the file not able to be deleted until garbage collection was run.  See the bug in the code comments for more details.

try
{
File f = null;
RandomAccessFile fis = null;
FileChannel fc = null;
ByteBuffer bb = null;
String printer = YOUR_PRINTER_NAME;
PrintService printService = PrintHelper.getPrintService(printer);

f = YOUR_PDF_FILE;
//Read only access would work too
fis = new RandomAccessFile(f, "rw");
fc = fis.getChannel();
bb = ByteBuffer.allocate((int)fc.size());
fc.read(bb);


//Do not map the file to a ByteBuffer as the examples show.
// There is a reason why in java bug #474038
// http://bugs.sun.com/view_bug.do?bug_id=4724038
//fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());
//bb = fc.map(FileChannel.MapMode.READ_WRITE, 0, fc.size());

PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
PDFPrintPage pages = new PDFPrintPage(pdfFile);
// Create Print Job
PrinterJob pjob = PrinterJob.getPrinterJob();
pjob.setPrintService(printService);

PageFormat pf = PrinterJob.getPrinterJob().defaultPage();

pf.setOrientation(PageFormat.PORTRAIT);

Paper paper = new Paper();

//This is to fix an error in PDF-Renderer
//View http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/ for details
//Printing a PDF is also possible by sending the bytes directly to the printer, but
//  the printer would have to support it.

paper.setImageableArea(0,0,paper.getWidth() * 2,paper.getHeight());

pf.setPaper(paper);

pjob.setJobName(f.getName());

Book book = new Book();
book.append(pages, pf, pdfFile.getNumPages());
pjob.setPageable(book);
pjob.print();

}
catch (FileNotFoundException e)
{
//do your error action
}
catch (IOException e)
{
//do your error action
}
catch (PrinterException e)
{
//do your error action
}
finally
{
try
{
if (fc != null)
{
fc.close();
fc = null;
}
}
catch (IOException e)
{
log.error(e);
//handle error here
}
try
{
if (fis != null)
{
fis.close();
fis = null;
}
}
catch (IOException e)
{
//handle error here
}
if (bb != null)
{
bb.clear();
}
}

Because this library has the bug that makes it not want to print in half size when printing a portrait-oriented PDF,  I cannot recommend using this library unless you find it is the only thing that will do the job.    Such obvious bugs that have been around for over a year point to unmaintained code or some other upstream issues.  Tune in tomorrow for another library that is maintained that will get the job done as well.

Tags: , ,

You’re trying to connect to an OS X box and your vnc viewer just doesn’t seem to work. Then, after many a google serch, you discover that OS X’s remote access protocol is incompatible with most VNC servers.  Tuning to Apple for help yeilds a solution, for a small(large) fee.

Thankfully, there is a better way.  There is a free VNC server for OS X called Vine.  Download it and install the server.  Now you should be able to connect through a typical VNC client.

Remember, if you use tightVNC to connect, use the F8 key to bring up the menu that allows you to switch to fullscreen and disconnect the session.

Tags: , ,

The storms that went through yesterday had an interesting effect on the available wifi networks in the area.   It wasn’t so much the storms that caused this, it was more the lack of power in the area when the lightning started striking.   Here is what the wireless situation looks like with and without power:

Before power goes out

Before power goes out

A UPS on internet equipment is something that I haven’t seen in too many places.  Apparently, not many people in my complex have heard of it either.

Power just went out

Power just went out

And finally, I win.  The Xantrax Xpower 400 actually kept the Internet up for over 8 hours after the power outage.

I stand alone

I stand alone

Of course, the server didn’t do as well, and I had to turn it down after 20 minutes.  It’s tough to have 99% uptime off of home DSL.

Tags: ,

Some content is taken from http://forums.ebay.co.uk/thread.jspa?threadID=1200182458.

I tried to link my ebay account to my paypal account and it would just simply not work. After going through the prompts many times, it would still say that there was no association. There is a fix in an odd location.

Go to account settings -> addresses
Click on all addresses
Then click on add paypal addresses

This gives yet another paypal login. After login, I was greeted with a message thanking me for creating a paypal account. Hmmm.

Tags: ,

Sometime, you just don’t know which dll files to register.  Enlighten yourself with dependancy walker .

Tags: , ,

They’ve been out for over a year, but I just stumbled upon them this week.  Redhat release some very high quality and non-encumbered fonts.   Most distibutions will have them in a package named liberated-fonts.  They are substitues for some very popular fonts such asTimes New Roman, Thorndale, Nimbus Roman, and Bitstream Vera Serif.  Check em out at https://www.redhat.com/promo/fonts/.

Tags: ,

Check out http://www.favicon.cc/ for your various favicon needs.

Tags: , ,

When double clicking on apps don’t seem to open the correct program anymore on almost every file, there is most likely an issue with the MIME database.  The MIME database tells the desktop environment which program should open a file.  Try this to re-associate things.

update-mime-database ~/.local/share/mime

This tip was found after searching the net and landing on this page.

Tags: , ,