LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (http://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Problem rsync, deletes all files target after first succesfull backup (http://www.linuxquestions.org/questions/linux-desktop-74/problem-rsync-deletes-all-files-target-after-first-succesfull-backup-4175497481/)

KEES01NED 03-08-2014 06:40 AM

Problem rsync, deletes all files target after first succesfull backup
 
Hi there,

I have the follwoing issue:
I use the following script file backup.sh:

#!/bin/sh
if [ -f "/media/backups/mounted" ]
then
rsync -rlptgo --delete --delete-excluded --exclude=**~ --exclude=**/*cache*/ --exclude=**/*Cache*/ --exclude=**/*trash*/ ~/ /media/backups/current/ --exclude=.* --log-file="/home/<user name>/Logfiles/rsync.log.$(date +%Y%m%d%H%m%S)" --verbose --update --itemize-changes
else
kdialog --title "Backup Failed" --passivepopup "Please connect hard drive and back up your data ASAP!" 3600 &
fi

When I execute the backup.sh from the terminal the first time every file will be copied to the target. I don't use sudo.

This is a subset of the log file:
2014/03/07 09:16:33 [2854] >f+++++++++ Secret of Nikola Tesla - The Movie (Tajna Nikole Tesle) (1980).avi
2014/03/07 09:16:33 [2854] >f+++++++++ backup.sh
2014/03/07 09:16:33 [2854] cd+++++++++ Desktop/
2014/03/07 09:16:37 [2854] >f+++++++++ Desktop/book.zip

Via "crontab -e", on 21:00 the backup is started automatically.
0 21 * * * /home/USERNAME/backup.sh

The second logfile looks like this:
2014/03/07 21:00:02 [5888] building file list
2014/03/07 21:00:02 [5889] building file list
2014/03/07 21:00:02 [5888] .d..tpog... ./
2014/03/07 21:00:02 [5888] *deleting tmp/simple/util.h

2014/03/07 21:00:02 [5888] *deleting Pictures/Selection_035.png
2014/03/07 21:00:02 [5888] *deleting Pictures/Selection_034.png
2014/03/07 21:00:02 [5888] *deleting Pictures/Selection_033.png
2014/03/07 21:00:02 [5888] *deleting Pictures/Selection_032.png
2014/03/07 21:00:02 [5888] *deleting Pictures/Selection_031.png
2014/03/07 21:00:02 [5888] *deleting Pictures/Selection_030.png

Somewhere in the middle of the logfile:

2014/03/07 21:00:06 [5889] rsync: recv_generator: mkdir "/media/backups/current/Downloads" failed: Permission denied (13)
2014/03/07 21:00:06 [5889] *** Skipping any contents from this failed directory ***
2014/03/07 21:00:06 [5889] cd+++++++++ Logfiles/
2014/03/07 21:00:06 [5889] rsync: recv_generator: mkdir "/media/backups/current/Logfiles" failed: Permission denied (13)
2014/03/07 21:00:06 [5889] *** Skipping any contents from this failed directory ***
2014/03/07 21:00:06 [5889] cd+++++++++ Music/
2

The result of all that is that the target directory is empty, everything has been deleted.

I changed the ownership of /media/backups/current before the auto backup to my user name and group. After the auto backup it seems to be root:root again???

What is wrong and why is the ownership changed?

PS I am relative new to Linux.

Regards

KEES01NED 03-09-2014 07:15 AM

Problem solved:

Check /var/log/syslog

Mar 8 21:00:01 KEMA-PC CRON[2663]: (root) CMD (/home/<my username>/backup.sh)
Mar 8 21:00:01 KEMA-PC CRON[2665]: (kees) CMD (/home/<my username>/backup.sh)

Mar 8 21:00:01 KEMA-PC rsyncd[2670]: rsync: failed to open log-file /home/<my username>/Logfiles/rsync.log.20140308210301: Permission denied (13)
Mar 8 21:00:01 KEMA-PC rsyncd[2670]: Ignoring "log file" setting.
Mar 8 21:00:01 KEMA-PC rsyncd[2670]: building file list
Mar 8 21:00:01 KEMA-PC rsyncd[2670]: rsync: writefd_unbuffered failed to write 4 bytes to socket [sender]: Broken pipe (32)

somehow crontab was started twice at the same time, one as root and one under my own user account. I Checked the internet and someone mentioned that if you use "sudo crontab -e" you create the root one and "crontab -e" you create your own. For both crontab's the following was entered "0 21 * * * *" start batchjob every day on 21:00. After deleting the line (the root one) with "0 21 * * * * " via comment "#" the problem was solved.

Conclusion never use "sudo crontab -e".

Regards Kees

unSpawn 03-09-2014 07:34 AM

Quote:

Originally Posted by KEES01NED (Post 5131441)
Conclusion never use "sudo crontab -e".

Sure you can but just ensure you add the user which crontab you want to edit if not your own:
Code:

crontab -e -u [username]


All times are GMT -5. The time now is 05:33 PM.