Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Advertise on LowEndTalk.com
Backuprar
New on LowEndTalk? Please read our 'Community Rules' by clicking on it in the right menu!

Backuprar

sc754sc754 Member
edited May 2014 in Tutorials

Hi,

Thought I'd post this short script I made for doing my own backups using rar. I made it so I could host my backups on openvz containers without worrying about my files being too available, like my emails. It's a script which takes an existing local backup file or folder, stores it as an encrypted rar archive with password and then push's it using rsync to another server. It doe's a couple of other things too. Any who here's the script.

Requires: rar, ssh (public key preferred if you plan to automate it with a cronjob), rsync

Edit... http://fs5.co.uk/backuprar.txt

Easier to just post it as a text then figure out formatting

Comments

  • raindog308raindog308 Administrator, Moderator

    said: Edit... anyone know how to format on this thing?

    You mean how to format on the interwebs?

    pre tag.

    The pre tag is easy and fun to use.
    

    For LET support, please visit the support desk.

  • sc754sc754 Member

    @raindog308 said:

    Doesn't come out nice using that..

  • raindog308raindog308 Administrator, Moderator

    sc754 said: Doesn't come out nice using that..

    #!/bin/bash
    #
    # backuprar.sh: A backup script to create and push a rar encrypted file to a remote server via rsync / ssh
    
    #
    # Path for cronjob from env, might want to check this path on your own vps if you set it
    #
    #PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
    
    # Backup a folder (Note: backup-$(date +%d-%m-%Y) = eg. backup-14-05-2014)
    #
    BACKUP=backup-$(date +%d-%m-%Y)
    
    # OR Backup a file
    #
    #BACKUP=mybackupfile.tar.gz
    
    # Local settings
    #
    PASSWORD=yourpasswordhere
    LOCALFOLDER=/home2/
    
    # Remote SSH host settings
    #
    REMOTEUSER=root
    IP=123.123.123.123
    PORT=22
    REMOTEFOLDER=/home/backups/
    
    #
    # Script start
    #
    
    DIRECTORYCHECK=$BACKUP
    cd $LOCALFOLDER
    if [ -f $DIRECTORYCHECK -o -d $DIRECTORYCHECK ];
    then
    rar a -hp$PASSWORD -m0 $BACKUP.rar $BACKUP
    sleep 2
    if [[ -s $BACKUP.rar ]] ; then
    rsync -e "ssh -p $PORT" -avzh $BACKUP.rar [email protected]$IP:$REMOTEFOLDER
    else
    rm -fR $BACKUP.rar
    fi ;
    else
    exit
    fi
    
    #
    # Script end
    #
    
    Thanked by 2sc754 Silvenga

    For LET support, please visit the support desk.

  • I recommend using something like a GitHub Gist. It might be easier for some (wget directly to their server). Gists also allows for community edits and bug fixes (and adds to your Github portfolio).

    :P

  • tommytommy Member

    use .tar.gz instead of rar, since tar installed by default on most of system.

    Let's bet which dot-name will collapse first ;)

  • GaNiGaNi Member

    @tommy said:
    use .tar.gz instead of rar, since tar installed by default on most of system.

    I am pretty sure the author has used rar to get a better compression result.

  • sc754sc754 Member

    @GaNi said:
    I am pretty sure the author has used rar to get a better compression result.

    Actually between tar.gz and rar there isn’t much difference in compression. The point of using rar is to encrypt the file which as far as I know isn’t possible with tar.gz

  • rds100rds100 Member

    If you want encryption, better use gpg, don't rely on rar's unknown and unverified algorithms.

    Thanked by 1raindog308

    -

  • Note that the "xz" format is not the "gz" format.

    "xz" has a higher compression ratio than "rar5" even in some benchmarks.

    "gz" on the other hand, balances fast, portable, and great compression ratio.

    Acting Director of Albino Geek Services Ltd. My Keybase ID ( gh )
    GoodHosting.co | Enterprise KVM Virtual Private Servers | Twitter / Status : @ GoodHostingCo

  • SilvengaSilvenga Member
    edited May 2014

    sc754 said: Actually between tar.gz and rar there isn’t much difference in compression. The point of using rar is to encrypt the file which as far as I know isn’t possible with tar.gz

    We should be using 7z.

    7z is much better than tar.gz, and rar in compression ratios. Bzip's huffmans table just cannot compare against 7z's compression dictionary.

    I would only use rar for it's recovery sectors - of which 7z, gz, xz, and zip lack.

  • sc754sc754 Member

    @Silvenga said:
    I would only use rar for it's recovery sectors - of which 7z, gz, xz, and zip lack.

    In my case and as per the script there is no rar compression (since my backups are already compressed in .tar.gz by virtualmin). But yeah you're right 7z is slightly better than rar on compression

  • sc754sc754 Member

    @rds100 said:
    If you want encryption, better use gpg, don't rely on rar's unknown and unverified algorithms.

    gpg is an alternative, I just personally use rar because it's user friendly on the windows side. rar uses AES256 as far as I know, so it's hardly an unknown and unverified algorithm

  • sc754 said: In my case and as per the script there is no rar compression (since my backups are already compressed in .tar.gz by virtualmin). But yeah you're right 7z is slightly better than rar on compression

    Make sense. Rar is also easier to increment backups than gz. Although I recommend keeping the use of tar (maybe even during a tar.rar) - because tar keeps the extended metadata (permissions, etc.) - for backups of linux systems.

    sc754 said: gpg is an alternative, I just personally use rar because it's user friendly on the windows side. rar uses AES256 as far as I know, so it's hardly an unknown and unverified algorithm

    He's talking more on the implementation side. Like SSL uses AES, but we all know what happened to OpenSSL. AES is considered safe, but there are always other ways to break the algorithms.

  • For automated backups encrypted by GnuPG I'm using Duply which is a wrapper for Duplicity. It uses rsync and can use quite a few storage backends including SCP, S3.

    I'm considering switching to Box Backup because instead of a cron task, it runs all the time so the backups are always up to date. Pretty interesting, but also one more service that's constantly running.

    Be seeing you.

Sign In or Register to comment.