4

I would like to synchronize all the content of my phone to my home server using the phone's samba share.

My approach is to write a script that mounts the phone's samba share, and then copies all the files on the phone to the specified directory. Then the script is ran every 10 minutes with crontab.

The first problem I am facing is that I would like the two folders (phone and server) to have a "contribute" relationship. This means that: new and updated files are copied from the phone to the server. Renames on the phone are repeated on the server. No deletions (if a file is deleted on the phone, it remains on the server). How can I achieve this? Maybe with rsync?

The second problem is: is there a better approach than trying to mount the samba share every 10 minutes to find out if the phone is connected or not to the wifi network?

2 Answers 2

0

Yes, rsync will do. But renames will result in a duplication if you do not take additional steps.

These could be: Make a list of transferred files, then check whether there is an existing file of the same size and content...

Part two: You should ping-check first before starting rsync. Or just use a small connection-timeout value with rsync.

Perhaps this old answer about a question how to compare with rsync might help you as well.

4
  • Do you know any tool like Microsoft SyncToy? It is a software for windows that does exactly what I want (contribute relationship between the two folders).
    – giovi321
    Jan 24, 2015 at 14:42
  • 1
    @giovi unison might go into the same direction.
    – Nils
    Jan 24, 2015 at 16:03
  • do you know what happens if the transfer is interrupted? Will it continue the transfer or will it start over again after?
    – giovi321
    Jan 24, 2015 at 16:21
  • @giovi321 rsync will do what it is told to do. By default it will not transfer files in-place. So if there is an interrupt, the target file will be to old one. If you restart rsync, it will do the same thing that it ever does: Look at both sides and then it will start to transfer the delta. There is a whole-file-mode as well as a partial file mode (see man rsync about details) - so it will either transfer whole files or just changes within files.
    – Nils
    Jan 24, 2015 at 20:48
0

I wrote a script to solve this. Some things are in Italian but i think you can easily understan how the scripts works. Anyway you can easily translate everything.

The script basically checks if the blackberry is connected to the network. If yes, it checks if a dummy file exists, if it does, it means that another istance of the script is already running so it exits. If no other istances are running, it checks when is the last time the script was ran (so not to backup the blackberry every 10minutes). If a dummy.file.time is older than 3 hours (10800 seconds), it starts the backup using rsync.

#!/bin/sh
# BlackBerry backup via SMB share
#
# Cosa fa lo script?
#
# Lo script fa il ping del blackberry
# Se il ping va a buon fine, controlla se esiste "$dummyfile"
# (per non eseguire più backup in parallelo).
# Se esiste "$dummyfile", controlla se "$dummyfiletime" è più
# vecchio di due ore (per non ripetere il backup in continuazione).
# Se "$dummyfiletime" è più vecchio di due ore, monta lo SMB share
# del blackberry e inizia il backup con rsync.
#


##### PARAMETERS START #####
logdate=$(date +"%m-%Y")
ip="192.168.1.5"
dummyfile="/media/truecrypt2/blackberry SMB Backup/dummy.file"
dummyfiletime="/media/truecrypt2/blackberry SMB Backup/dummy.file.time"
monta="mount -t cifs -o username=USER,password=PASSWORD //$ip/media/ /media/blackberrySMB/"
sincronizza="rsync -a /media/blackberrySMB /media/truecrypt2/blackberry\ SMB\ Backup"
scriptlog="/var/log/blackberrySMBbackup/script_$logdate.log"
rsynclog="/var/log/blackberrySMBbackup/rsync_$logdate.log"
dummyfiletimeage=$(( `date +%s` - `stat -L --format %Y "$dummyfiletime"` )) #age of the dummy.file.time
defaultage="10800" #in seconds
###### PARAMETERS END ######

echo "$(date +"%D %T") : BlackBerry SMB backup lanciato." >>$scriptlog
echo "Effettuo ping verso $ip" >>$scriptlog
if fping -c 1 -t 500 $ip >>/dev/null
then
  echo "Risposta al ping ricevuta da $ip" >>$scriptlog
  if [ -f "$dummyfile" ]
  then
    echo -e "dummy.file esistente. Forse il processo e gia in esecuzione. Esco.\n" >>$scriptlog
    exit
  else
    echo "dummy.file non esistente. Controllo se dummy.file.time e piu vecchio di 3 ore." >>$scriptlog
    if [ "$dummyfiletimeage" -gt "$defaultage" ]
    then
      echo "dummy.file.time e piu vecchio di 3 ore. Inizio il backup." >>$scriptlog
      touch "$dummyfile"
      rm "$dummyfiletime"
      touch "$dummyfiletime"
      umount //$ip/media/
      umount //$ip/media/
      $monta
      echo "$(date +"%D %T") : BlackBerry SMB rsync lanciato." >>$rsynclog
      rsync --verbose -a /media/blackberrySMB /media/truecrypt2/blackberry\ SMB\ Backup >>$rsynclog
      echo "***************************" >>$rsynclog
      umount //192.168.1.5/media/
      rm "$dummyfile"
      echo -e "Backup completato. Esco.\n" >>$scriptlog
      exit
    else
      echo -e "dummy.file.time e piu recente di 3 ore. Esco.\n" >>$scriptlog
      exit
    fi
  fi
else
  echo -e "Nessuna risposta al ping da $ip. Blackberry non connesso. Esco.\n" >>$scriptlog
  exit
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .