I wrote a bash-script with the intention to back up a specific (truecrypt-)file onto a SD-card (and a folder shared over the cloud) using the rsync command.
The problem was that the SD-card usually wasn't mounted yet and thus the synchronization didn't work. So I wrote a script that mounts the card, syncs the file and should unmount it again. Script:
sudo mkdir /media/user_name/SDcard
sudo mount -t vfat LABEL="SDcard" /media/user_name/SDcard
rsync -avI /home/user_name/Dokumente/file_to_sync /media/user_name/SDcard
rsync -avI /home/user_name/Dokumente/file_to_sync /home/user_name/cloudbox
sudo umount /media/user_name/SDcard
sudo rmdir /media/user_name/SDcard
While the synchronization to the cloudbox works properly, the sync to the SDcard does not. Furthermore the umount and the rmdir commands both are not executed. The result being that the following time I use the script, there is an error because the directory already exists.
When all commands are executed manually and in succession in the terminal, the rsync command (with sudo) to the SDcard gives an error message:
user_name@host ~ $ sudo rsync -av ~/Dokumente/file_to_sync /media/user_name/SDcard/file_to_sync
sending incremental file list
rsync: chown "/media/user_name/SDcard/.file_to_sync.tK2RnM" failed: Operation not permitted (1)
sent 524,416,101 bytes received 127 bytes 61,696,026.82 bytes/sec
total size is 524,288,000 speedup is 1.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1183) [sender=3.1.0]
Strangely, if I mount the SDcard by double clicking on the desktop icon instead of using sudo mount ..., I can synchronize the file without any problems.
What is wrong with my script? I have tried several modifications, but none worked (better).
Why is there a difference between the mounting by double clicking and the mounting in the terminal and what is it? How could I "reproduce" the "double-click-command" in the terminal?
I have been trying to get this to work for quite some time now and forums and tutorials etc. could not help me out. So I'd appreciate any tiny little bit of help anyone can give...
My System: Linux Mint 17 (originally Cinnamon but changed to XFCE) on a Lenovo T440p with CORE i7vPro, 250 GB SSD, 12 GB RAM (and the worst touchpad I have ever encountered)