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'm writing a backup script in BASH on a linux machine (gentoo)

The script will backup all folders in a certain directory.

The folders will have varying privileges and belong to different users and groups.

In order to make sure my backup script has read privileges to all the the files and folders I'm tempted to run the backup script as root.

Is this safe? Are there any specific techniques to achieve this without root privileges?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

cron is the best way to do that, and yes certain scripts need to run with root otherwise you are not able to read from users home directory with 700 privileges.

share|improve this answer
add comment

It's very hard to make bash scripts safe when running as root. Be very careful that you've got the script bullet proof. Check the return codes of all commands if their failing can have bad effects.

I'd usually recommend a scripting language such as perl, python, ruby etc, which are easier to make safe.

share|improve this answer
3  
"recommend a scripting language such as..." What's bash then, chopped liver? –  womble Oct 4 '09 at 23:57
    
People write bad scripts in every language (though, usually perl). For a task like this you should just use whatever you're most comfortable with (and really there shouldn't be much to script, let rsync or something else designed to make backups do the hard work). –  theotherreceive Oct 5 '09 at 2:44
    
@gorrila, I have considered writing a seperate script that only handles the parts that require all user privilages... I understand your concern about BASH but I odn't think it's BASH as much as how BASH is often misused that makes it insecure –  Fire Crow Oct 5 '09 at 17:14
    
i wrote bash script to backup huge amount of data all across servers(~600 hosts) without problem. there is nothing like using tool a or b makes it secure but the way of using it. –  Istvan Oct 14 '09 at 17:02
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.