1

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?

2 Answers 2

3

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.

-2

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.

4
  • 3
    "recommend a scripting language such as..." What's bash then, chopped liver?
    – womble
    Oct 4, 2009 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). Oct 5, 2009 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, 2009 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, 2009 at 17:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .