Safe to run backup script as root? or other way to aproach privileges? – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.
But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about linux, backup, permissions, scripting, .
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.