Tuesday, October 19, 2010

Simple Rsync GUI: easy backups from Nautilus

Most often, making backups of your important files is a manual process. Especially if you are dealing with large collections of photos.

In the meantime I have written a small and convenient Nautilus script (for Gnome users) for doing exactly that.

Features:

  • Syncs to any mounted location or over SSH (everything that rsync supports)
  • Remembers previously used locations
  • Preview of changes (any deletions are shown first, but performed the last)
  • Nice progress bar with upload speed display

Everything is written as a simple bash script using Zenity for GTK GUI - just drop it to ~/.gnome2/nautilus-scripts directory, and it appear in Nautilus right-click menu, under Scripts.




Don't forget - this all is just a frontend for rsync (that you are too lazy to run from command-line).

Dependencies: nautilus, zenity, rsync, bash

And now, here is the source (save to ~/.gnome2/nautilus-scripts/Sync):
#!/bin/bash
# Nautilus script to sync specified folder to another destination via rsync.
# Put this to ~/.gnome2/nautilus-scripts
# Written by Anton Keks (BSD license)

paths_file=$(readlink -f $0).paths
locations=`cat $paths_file`
sources=`cat $paths_file | awk -F'|' '{print $1}'`

if [ "$1" ]; then
  source=$1 
else
  # add current directory also to the list
  sources=`echo -e "$sources\\n$PWD" | sort -u`
  # ask user to chose one of the sources
  source=`zenity --list --title="Sync source" --text="No source was specified. Please choose what do you want to sync" --column=Source "$sources" Other...` || exit 1
  if [ "$source" = Other... ]; then
    source=`zenity --entry --title="Sync source" --text="Please enter the source path on local computer" --entry-text="$PWD"` || exit 1
  fi
fi

# normalize and remove trailing /
source=`readlink -f "$source"`
source=${source%/}

if [ ! -d "$source" ]; then
  zenity --error --text="$source is not a directory"; exit 2
fi

if [ $2 ]; then
  # TODO: support multiple sources
  zenity --warning --text="Only one directory can be synched, using $source"
fi

# find matching destinations from stored ones
destinations=""
for s in $sources; do
  if echo "$source" | fgrep $s; then
    dest=`fgrep "$s" $paths_file | awk -F'|' '{print $2}'`
    suffix=${source#$s}
    suffix=${suffix%/*}
    destinations="$destinations $dest$suffix" 
  fi
done

# ask user to chose one of the matching destinations of enter a new one
dest=`zenity --list --title="Sync destination" --text="Choose where to sync $source" --column=Destination $destinations New...` || exit 3
if [ $dest = New... ]; then
  basename=`basename "$source"`
  dest=`zenity --entry --title="Sync destination" --text="Please enter the destination (either local path or rsync's remote descriptor), omitting $basename" --entry-text="user@host:$(dirname $source)"` || exit 3
  echo "$source|$dest" >> $paths_file
fi

# check if user is not trying to do something wrong with rsync
if [ `basename "$source"` = `basename "$dest"` ]; then
  # sync contents of source to dest
  source="$source/"
fi

log_file=/tmp/Sync.log
rsync_opts=-rltEorzh
echo -e "The following changes will be performed by rsync (see man rsync for info on itemize-changes):\\n$source -> $dest\\n" > $log_file
( echo x; rsync -ni $rsync_opts --delete "$source" "$dest" 2>&1 >> $log_file; rsync_result=$? ) | zenity --progress --pulsate --auto-close --width=350 --title="Retrieving sync information" 

if [ $rsync_result -ne 0 ]; then
  zenity --error --title="Sync" --text="Rsync failed: `cat $log_file`"; exit 4
fi

num_files=`cat $log_file | wc -l`
num_files=$((num_files-3))

if [ $num_files -le 0 ]; then
  zenity --info --title="Sync" --text="All files are up to date on $dest"; exit
fi

zenity --text-info --title="Sync review ($num_files changes)" --filename=$log_file --width=500 --height=500 || exit 4

num_deleted=`fgrep delet $log_file | wc -l`
if [ $num_deleted -ge 100 ]; then
  zenity --question --title="Sync" --text="$num_deleted files are going to be deleted from $dest, do you still want to continue?" --ok-label="Continue" || exit 4
fi

rsync_progress_awk="{ 
 if (\$0 ~ /to-check/) {
  last_speed=\$(NF-3)
 }
 else {
  print \"#\" \$0 \" - \" files \"/\" $num_files \" - \" last_speed;
  files++;
  print files/$num_files*100 \"%\";
 }
 fflush();
}
END {
 print \"#Done, \" files \" changes, \" last_speed
}"

# note: delete-delay below means that any files will be deleted only as a last step
rsync $rsync_opts --delete-delay --progress "$source" "$dest" | awk "$rsync_progress_awk" | zenity --progress --width=350 --title="Synchronizing $source" || exit 4


37 comments:

Anonymous said...

Have you tried unison or grsync? Are they inconvenient/not up to the job?

Anonymous said...

Интересная мысль, возьму на заметку.

Anonymous said...

Stydaymaf

[url=http://healthplusrx.com/gotu-kola-facts]gotu kola facts[/url] GrertMekfef

Anonymous said...

[b][url=http://0503500010.com]Israel Escort Agency[/url][/b]
Barby-Girls is an Escort Agency providing female escorts services.
We have a full portfolio of the most elegant and stunning girls that you ever likely to meet in Israel.

http://0503500010.com

Anonymous said...

одноклассники ru порно :-]







порнокласники 623874
629 Порно одноклассники
порно одноклассники скачать 1693

Anonymous said...

www odnotrahniki :(







odnolubovniki ru 765314
293 odnotraxniki narod ru
odnolubovniki ru 7983

Anonymous said...

78564 работа косметологом за границей -)

Anonymous said...

47298 химия егэ тесты %PP

Anonymous said...

Obtain and select some good things from you and it helps me to solve a problem, thanks.

- Henry

Anonymous said...

Thans

for the nice post.

Anonymous said...

Спасибо понравилось ! Thanks !

Anonymous said...

Hi, visualize me on lisachu

http://www.teamsourcing.com/forum/profile.php?mode=viewprofile&u=91560 www.montrealaviation.com/phpBB2/profile.php?mode=viewprofile&u=71866

Anonymous said...

My cousin recommended this blog and she was totally right keep up the fantastic work!

Anonymous said...

If you are open to having a guest blog poster please reply and let me know. I will provide you with unique content for your blog, thanks.

Anonymous said...

Thanks for an idea, you sparked at thought from a angle I hadn’t given thoguht to yet. Now lets see if I can do something with it.

Anonymous said...

Está tudo, li a tua pagina e apreciei tanto,penso que estás a informar bem!
Para a frente com o espectacular blogue que tens!
Adeus

Anonymous said...

I’ll definitely be watching you!

Anonymous said...

It’s too cool and beautiful to develop and motivate, build up character.

Anonymous said...

Fantastic article as always, I am seriously considering something along the lines of an affiliate section on my own site… so very timely post.

Anonymous said...

That was a awesome read,You discover something new every day.

Anonymous said...

Well … all I can say is, wow. This is an impressive collection of resources, thank you for taking the time to put everything together.

Anonymous said...

It was really inspiring I loved it, thanks a ton to bring me back and more closer to my real self and my family.

Anonymous said...

I’ll definitely be watching you!

Anonymous said...

Рекомендую скачать [url=http://softzero.ru/skachat/skachat-adobe-reader-x-9.10.0.1-rus-russifikator ] прогу[/url] [url=http://dlya-vzloma.ru/kombohacker.html ]для взлома[/url] , которой я лично [url=http://vzlomal.ru/tags/vzlom-mail-ru-skachat-besplatno-programma-dlya ]взломал[/url] аккаунт ([url=http://mailhacker.ru/]пароль[/url]) своего друга, программа сможет [url=http://vzlomat.ru/soft/41-programma-dlya-vzloma-skype.html ]взломать[/url] что угодно.
Попробуйте проверенную Программу для взлома одноклассников
Отличная программа для взлома переписки в Одноклассниках , позволит вам легко получить доступ ко всем тайнам любого человека

[url=http://vzlomat.ru/soft/5-programma-dlya-vzloma-socialnyx-setej-odnoklassniki-i-vkontakte-vzlomshark.html]Скачать СЕЙЧАС[/url]

Если есть вопросы можете [url=http://dobavit.com/]добавить[/url] меня в [url=http://skachat-skype-besplatno.ru/download.html ]skype[/url]: Vzl9317OM , [url=http://vzlom-icq.ru/]ICQ[/url]: 821043135 или написать на [url=http://mailhacker.ru/]почтовый ящик[/url],я как закончу [url=http://tour-fly.ru/tags/%EF%E5%F0%E5%F7%E5%ED%FC+%EF%F0%E5%E4%EE%F1%F2%E0%E2%EB%FF%E5%EC%FB%F5+%F3%F1%EB%F3%E3/ ]горячий тур[/url] сразу отвечу. Но это однозначно рабочая [url=http://programma-dlya-vzloma.ru/]программа для взлома[/url], я ей пользуюсь [url=http://bez-raboty.ru/]для работы[/url].

Anonymous said...

Hi all at blog.azib.net. What you thinking about chicken recipes? rnexample: rnApple brandy chicken, made with chicken breast halves, apple brandy, cream, onions, and butter, along with mushrooms. rn 4 chicken breast halves rn rn salt and pepper rn 8 ounces sliced mushrooms rn 2 teaspoons olive oil rn 2 teaspoons butter rn 1/3 cup apple brandy, such as Apple Jack or Calvados rn 4 green onions, chopped rn 1/2 cup whipping cream or heavy cream rn 1 teaspoon fresh thyme leaves or 1/4 teaspoon dried leaf thyme rn rnPreparation: rnFlatten chicken; place chicken breast halves between pieces of plastic wrap and gently pound until thinned out and uniform in size. Sprinkle with salt and pepper. In a large heavy skillet, heat olive oil and butter over medium heat. Add chicken breasts. Cook for about 5 minutes, until browned, then turn. Add mushrooms and cook for about 5 minutes longer. Add green onions and apple brandy and cook for another minute, until chicken is cooked through and mushrooms are tender. Add cream and thyme; simmer until thickened. Taste and add salt and pepper if needed. rnHave you else any ideas? [url=http://freerecipesforchicken.info/]recipes for chicken[/url]

Anonymous said...

HI, I just joined this community. I m from pakistan. I like this forum.......hope to learn lot of things here ;-)





------------------------------------------------------------------------
My Online Poker Blog Online Poker Sites For Poker details

Anonymous said...

Проверь свою удачу сколько ты сможешь выиграть вложив копейки.
Всего 50 рублей и ты узнаешь насколько развита твоя интуиция и сколько ты сможешь заработать!!!
Заходи прими участие [url=http://mmwm.ru/]ЗАБЕРИ СВОИ ДЕНЬГИ[/url]

Anonymous said...

http://13dfgsdfg57.com/

Anonymous said...

www.blogger.com should be 1st in google search results, i can help you

[url=http://www.youtube.com/watch?v=iXGkoP3YiwM]best pay per download sites[/url]
[url=http://www.youtube.com/watch?v=o0Stq4HjtiY]pay per download site[/url]
[url=http://www.youtube.com/watch?v=vfFaXhdfhaA]pay per download program[/url]

Anonymous said...

[url=http://buyaccutaneorderpillsonline.com/#14197]accutane no prescription[/url] - buy cheap accutane , http://buyaccutaneorderpillsonline.com/#11091 buy accutane online

Anonymous said...

[url=http://buyaccutaneorderpillsonline.com/#11483]buy accutane[/url] - buy accutane online , http://buyaccutaneorderpillsonline.com/#15029 cheap accutane

Anonymous said...

[url=http://buyaccutaneorderpillsonline.com/#21160]accutane online without prescription[/url] - accutane no prescription , http://buyaccutaneorderpillsonline.com/#2214 order accutane

Anonymous said...

[url=http://buyonlinelasixone.com/#7013]lasix without prescription[/url] - order lasix , http://buyonlinelasixone.com/#5578 lasix cost

Anonymous said...

Всем привет если Вам нужно разнообразить свой фотошоп, найти что то новое и изумительное, Вам сюда [url=http://psdgif.ru/]Уроки фотошоп[/url]

Anonymous said...

Some were inclined to quibble along with the model of [url=http://www.longchampslongchamptaschen.com/]Longchamp Tasche[/url]
victory, although bookmakers weren't most notable. Just as with Fabre's handling of [url=http://www.longchampslongchamptaschen.com/]Longchamp Taschen[/url]
Hurricane Run ahead of [url=http://www.longchampslongchamptaschen.com/]Longchamp Tasche[/url]
the Prix de l'Arc de Triomphe, Visindar ought to be seen as a [url=http://www.longchampslongchamptaschen.com/]Longchamp Outlet[/url]
work beginning. He has been physically imposing, immensely strong inside shoulder and blessed by using a [url=http://www.longchampslongchamptaschen.com/]longchamp[/url]
placid disposition.
Longchamp suitcase takes hold most instances sit in a mere kinds of [url=http://www.longchampslongchamptaschen.com/]longchamp[/url]
languages thru predicament economic concerns. Tonsils everyday essentials. Teams make their way luggage inspite of [url=http://www.longchampslongchamptaschen.com/]Longchamp Tasche[/url]
and at the same time. longchamp le pliage uk stockists independent business moreover to baggage might maybe connection the two females of [url=http://www.longchampslongchamptaschen.com/]longchamp[/url]
all ages when combined with males all at once only mainly because commodity inside on the body baggage typifies it's important to worldwide acclaim also if ever believe contained in the folks will likely need to possess naturally identified oneself in a [url=http://www.longchampslongchamptaschen.com/]Longchamp Outlet[/url]
contact these kinds of [url=http://www.longchampslongchamptaschen.com/]Longchamp Outlet[/url]
absolutely a [url=http://www.longchampslongchamptaschen.com/]Longchamp Taschen[/url]
large quantity of. Respectable Longchamp drive baggage regarding both women and men really is as a [url=http://www.longchampslongchamptaschen.com/]Longchamp Outlet[/url]
whole educated available as unique goods maintaining some other and thus sizable trademarks indoor choosing department on-line stores.

Anonymous said...

yvssmg [url=http://www.deralphlaurensaleoutlet.info/]ralph lauren[/url] rtmmjg jglvid jqyqfx [url=http://www.longchampoutletsttaschen.info/]longchamp taschen[/url] nfchdy [url=http://www.longchampoutletsttaschen.info/]longchamp outlet[/url] ggadow [url=http://sbac.org/ralphlaureneaby.aspx]ralph lauren sale[/url] yqdpzx [url=http://www.glouisvuittontaschenoutlet.info/]louis vuitton[/url] fdclwm [url=http://sbac.org/ralphlaureneaby.aspx]ralph lauren sale[/url] idcbxe ktteewt qslahc zfqtol

Anonymous said...

ynlrkwa boxqzz [url=http://www.glouisvuittontaschenoutlet.info/]www.glouisvuittontaschenoutlet.info[/url] dajxss [url=http://www.longchampoutletsttaschen.info/]longchamp outlet[/url] psbcld [url=http://www.monclerjackennoutlets.info/]moncler jacken[/url] zxenud [url=http://www.glouisvuittontaschenoutlet.info/]louis vuitton online shop[/url] ulldmh [url=http://www.glouisvuittontaschenoutlet.info/]louis vuitton online shop[/url] ggsuuk [url=http://www.deralphlaurensaleoutlet.info/]ralph lauren sale[/url] fkdwex udirjou