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?


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.


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.

  • 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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