Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to disable the requirement of sudo or running as root for a bash script that does backups with tar.

I added this line to my sudoers file

username ALL=NOPASSWD: /bin/tar

However after I added that it still shows permissions denied when I run this backup command

/bin/tar -cvpzf /root/sysBackup/backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /

These are the errors

/bin/tar: Removing leading `/' from member names                                                                                                          
tar (child): /root/sysBackup/backup.tar.gz: Cannot open: Permission denied                                                                                
tar (child): Error is not recoverable: exiting now        

What am I doing wrong?

share|improve this question
2  
You still need to run it as root, are you typing sudo first? –  Sirch May 2 '12 at 16:32
add comment

1 Answer

up vote 5 down vote accepted

You still need to start your tar command via sudo inside your bash script:

sudo /bin/tar -cvpzf /root/sysBackup/backup.tar.gz --exclude=/backup.tar.gz --exclude=/proc --exclude=/lost+found --exclude=/sys --exclude=/mnt --exclude=/media --exclude=/dev /
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.