lockquote>

With 5Gb of free space, Google Drive could be a good option for simple backups of small servers and desktops.

We’ll use Grive for Google Drive support and a small script that you can adjust for your needs.

Installing Grive

On Debian:

apt-get install grive

On Ubuntu:

We’ll be using PPA Repositories.

sudo add-apt-repository ppa:nilarimogard/webupd8
sudo apt-get update
sudo apt-get install grive

Preparing

Create a directory and enter it:

mkdir /mnt/GoogleDrive
cd /mnt/GoogleDrive

Run the grive command with the option -a to prepare and get authorization:

# grive -a
-----------------------
Please go to this URL and get an authentication code:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+https%3A%2F%2Fdocs.google.com%2Ffeeds%2F+https%3A%2F%2Fdocs.googleusercontent.com%2F+https%3A%2F%2Fspreadsheets.google.com%2Ffeeds%2F&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&client_id=22314510474.apps.googleusercontent.com

-----------------------
Please input the authentication code here:

Copy and paste the link into your browser, being sure to be logged on the right Google Account to access the Drive you need. Copy and paste back the authentication code, and is done – first sync will be done.

Warning: only “real” files will be synced – grive doesn’t support download of Google Apps editable docs.

Script

This script reads a directory to sync with GoogleDrive.

Create the following script in /SOMEPATH/googledrive-sync.sh and give it permission to execute (chmod 755 /SOMEPATH/googledrive-sync.sh)

#!/bin/bash
# Google Drive Sync
#
# Author: Rafael Goulart <rafaelgou@gmail.com>
#
# Config BEGIN
# =====================================================================

# Directory to backup
BACKUPDIR=/var/backups

# Google Drive directory
GDRIVEDIR=/mnt/GoogleDrive

# Directory target in remote
TARGETDIR=/backups

# =====================================================================
# Config END

# Create backup dir if not exists
echo Creating ${GDRIVEDIR}/${TARGETDIR} if needed
if [ ! -d "${GDRIVEDIR}/${TARGETDIR}" ]; then mkdir ${GDRIVEDIR}/${TARGETDIR}; fi

# Moving to Gdrive Dir
echo Entering ${GDRIVEDIR}
cd ${GDRIVEDIR}

# Initial sync
echo Initial Google Drive Sync
grive

# Coping new content
echo Copying from ${BACKUPDIR}/* to ${GDRIVEDIR}/${TARGETDIR}/
cp -R ${BACKUPDIR}/* ${GDRIVEDIR}/${TARGETDIR}/

# Showing files copied
echo Files to sync
find ${GDRIVEDIR}/${TARGETDIR}/

# Final sync
echo Final Google Drive Sync
grive

You have 3 parameters:

  • BACKUPDIR: Directory to backup – put your stuff here, make a script to compact your data befoe – default /var/backups
  • GDRIVEDIR: Google Drive directory you’d created before – default /mnt/GoogleDrive
  • TARGETDIR: Directory target in remote, it will be crated to not mess up your Drive – default /backups

Put this file in your crontab:

ln -sf /SOMEPATH/googledrive-sync.sh /etc/cron.dayly/

or run it manually:

/SOMEPATH/googledrive-sync.sh

Warnings and Tips

  • Be aware of the limitations of Grive
  • You can save some disk space doing your backup directly on /mng/GoogleDrive/backups and only running grive after doing it. I prefered the 2 steps as suggested, but it’s up to you

Update

If the following command does not exist (Ubuntu 12.04)

sudo add-apt-repository ppa:nilarimogard/webupd8

install with:

sudo apt-get install python-software-properties

The problem

Convert .doc, .odt, .docx files to .pdf, or another combination (i.e. .docx to .odt)
under PHP.

To solve this problem we’ll install Unoconv,
LibreOffice command tools and build a PHP Class.

Installing

Unoconv is Python tool that uses LibreOffice libs (pyuno).

Instaling LibreOffice command line tools

On a server you’re not required to make a full install of LibreOffice,
just command line and converters that you find on core.

For Ubuntu/Debian:

apt-get install openjdk-6-jdk libreoffice-core libreoffice-common libreoffice-writer python-uno

Important:

Installing libreoffice-writer gives you support to convert TEXT documents.
To convert other formats (spreadsheets, presentations, images, etc), install the related LibreOffice package.

For images, consider lighter and well-known tools such ImageMagick;

For converting PDF to Text, consider PDF to Text – you can find it in Poppler-Utils package.

Installing o Unoconv

Installing libreoffice-writer gives you support to convert TEXT documents.
To convert other formats (spreadsheets, presentations, images, etc), install the related LibreOffice package.

For images, consider lighter and well-known tools such ImageMagick;

For converting PDF to Text, consider PDF to Text – you can find it in Poppler-Utils package.

Installing o Unoconv

As root:

cd /tmp
git clone https://github.com/dagwieers/unoconv
cd unoconv/
make install
cd ../
rm -rf unoconv/
unoconv --listener &

So you’ve started LibreOffice/OpenOffice as a service running on a local port,
and you can check with ps aux | grep soffice.

Some warnings:

  • Unlike you can convert only with a LibreOffice/OpenOffice install, using the
    service and unoconv is better for mass intensive operations, because you
    reuse an instance always in memory.

  • unoconv package is already in Debian repositories but that’s an old version.

Showing support formats

unoconv --show

Creating a Deamon

To demonize unoconv (better for server mode), create a file /etc/init.d/unoconvd with the following content:

( Fonte )

#!/bin/sh
### BEGIN INIT INFO
# Provides: unoconvd
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop:
# Description: unoconvd - Converting documents to PDF by unoconv
### END INIT INFO
case "$1" in
    start)
        /usr/bin/unoconv --listener &
        ;;
    stop)
        killall soffice.bin
        ;;
    restart)
        killall soffice.bin
        sleep 1
        /usr/bin/unoconv --listener &
        ;;
esac

The adjust permissions, put on boot and run the daemon:

chmod 755 /etc/init.d/unoconvd
update-rc.d  unoconvd defaults
service unoconvd start

Basic use

It doesn’t matter if you’ve started unoconv manualy or deamonized, you can
use as bellow to convert files:

unoconv --format pdf --output /OUTPUT_DIR/ file.odt

That will convert the file.odt to file.pdf on the informed output directory.

PHP Class

A simple PHP wrapper could be as bellow:

<?php

namespace Unoconv;

/**
* Unoconv class wrapper
*
* @author Rafael Goulart <rafaelgou@gmail.com>
* @see http://tech.rgou.net/
*/
class Unoconv {

    /**
    * Basic converter method
    * 
    * @param string $originFilePath Origin File Path
    * @param string $toFormat       Format to export To
    * @param string $outputDirPath  Output directory path
    */
    public static function convert($originFilePath, $outputDirPath, $toFormat)
    {
        $command = 'unoconv --format %s --output %s %s';
        $command = sprintf($command, $toFormat, $outputDirPath, $originFilePath);
        system($command, $output);

        return $output;
    }

    /**
    * Convert to PDF
    * 
    * @param string $originFilePath Origin File Path
    * @param string $outputDirPath  Output directory path
    */
    public static function convertToPdf($originFilePath, $outputDirPath)
    {
        return self::convert($originFilePath, $outputDirPath, 'pdf');
    }

    /**
    * Convert to TXT
    * 
    * @param string $originFilePath Origin File Path
    * @param string $outputDirPath  Output directory path
    */
    public static function convertToTxt($originFilePath, $outputDirPath)
    {
        return self::convert($originFilePath, $outputDirPath, 'txt');
    }

}

Sample use:

<?php
/**
* Sample use of Unoconv class
*  
*/
require 'Unoconv.php';

use Unoconv\Unoconv;

// Converting to PDF
$originFilePath = 'test.odt';
$outputDirPath  = './';
Unoconv::convertToPdf($originFilePath, $outputDirPath);

// Converting to DOCX
$originFilePath = 'test.odt';
$outputDirPath  = './';
Unoconv::convert($originFilePath, $outputDirPath, 'docx');

CDN (Content Delivery Network) are distribuited servers across the internet that server your site not only with redundancy, but througth the nearest way to your end client.

This service is used for large websites and companies. But we can use part of these services for free and speed up our sites and apps. Let’s learn why.
Read more »

On my quest to find a way to render my Markdown and restructuredText docs on the fly, I’d found a lot of useful tools.

Markdown is my favorite lightweigth markup language. This blog is writen mostly in Markdown, thanks to Markdown on Save Worpress Plugin. I use it also for writtting simple tutorials, or step-by-step installation notes, or just to keep some tips for RegEx, for example.

And restructuredText can be used for the same uses, and thanks to some powerful options, is great to write long documentation, or even a book (Symfony2 docs and books are writen in restructuredText).

But… it’s so good to write docs using this markup languages, but NOT so good to read on that. It’s a must to convert or render them into another format, such HTML, ePub, PDF, etc.

So, what do I do? I use some tools, depending of my need. Read more »

You are used to – just like me – write tutorials, step-by-step install scripts, personal notes in Markdown or Restrutured Text, but get depressed when need to read them on pure text?

While I was thinking about it, I’d glued some pieces of open source software to create a simple renderer for this two formats:

DocRenderer no GitHub

Pay special atention to this tip to create a renderer for directory full of .md‘s and .rst‘s:

Rendering a full directory