Skip to:

Tiago Cogumbreiro

O Irrepupável

Back to top

Backup On The Fly

My brother changed its disk, so I backed up his directory in my computer. After he installed his new and cool operating system of choice he wanted his stuff back. Uploading it through the net was not a very good option because sftp and scp are not really the best tools for the job. I could do an ssh tar c /path/to/backup | tar x to maintain the integrity, but having a backup of your files haven't hurt anyone yet ;)

The problem here is that my disk is full, so creating a 4GB based iso is out of the question. Also creating an iso directly from a directory does not maintain filesystem integrity. The only solution was trying to tar my directory, feed it to mkisofs ad the only file in it and pipeing it through growisofs:

# Get the number of sectors the tar will ocupy
get_sectors () {
    expr $("$@" | wc -c) / 2048 + 1
}
one_file_iso () {
    local SECTORS=$(get_sectors "$@")
    "$@" | growisofs -Z /dev/dvd -stream-media-size $SECTORS
}
# Run the command
one_file_iso tar c path/to/backup
# Could also be done with rar/zip/bzip2
# one_file_iso tar jc path/to/backup
So basically this shell function generates an iso with a single file which is the content of one command.

Warning: this script will run the given program twice!


Tags used:

Back to top