I'm writing a shell script that will make backups of my system ( like this: https://help.ubuntu.com/8.04/serverguide/C/backup-shellscripts.html ).
What is the best location in my system, to store this file? I know, I can put it anywhere, but what will be if it will be stored in a directory being backed up? What is the best practice here?
I'm running an Ubuntu-server.
As others have said, under /usr/local/ , not /opt/. I usually also have these sorts of scripts in /root/ , but that can be considered bad practice. One possibility is also /etc/cron.daily/ .
But you really should be asking yourself why you are doing this. Homegrown backup scripts are easier to get wrong than some off-the-shelf backup solution. And remember, you don't want backups, you want working restores.
Some people install additional stuff in /usr/local others in /opt.
See: http://www.pathname.com/fhs/
I have a separate user account on my home machine for tasks like backups, anti virus scans etc.
Jobs like backup.sh go in that home directory. The advantage of doing this is that it is easy then to backup without having to back up all of /usr/ to catch a few bespoke scripts.
On servers /usr/local/sbin/ for system binaries or /usr/local/bin/ for other scripts is fairly standard.
/opt/ can be used but is usually for third party applications.