LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 03-08-2014, 05:40 AM   #1
KEES01NED
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Rep: Reputation: Disabled
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
 
Old 03-09-2014, 06:15 AM   #2
KEES01NED
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
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
 
Old 03-09-2014, 06:34 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by KEES01NED View Post
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]
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
using rsync to backup files newbie0101 Linux - Software 1 01-08-2012 02:21 PM
rsync: only backup recently modified files hamish Linux - Software 3 09-20-2011 09:55 AM
LXer: How to use rsync to copy files, folders, and to backup in Linux LXer Syndicated Linux News 0 03-01-2011 12:00 AM
Dead Laptop RAM: How to backup files with Rsync? fragged Linux - Newbie 5 08-23-2009 01:43 PM
rsync backup problem keenboy Linux - Software 2 03-20-2009 09:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 11:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration