Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am running Ubuntu server 12.04 LTS. After many trials and errors, the backup strategy I have selected resorts to using TAR (mostly because I was unable to find a tool to backup/restore dovecot mailboxes to an archive rather than mirror it to another server).

The plan is to shutdown services for the shortest possible duration when the backup is ongoing.

I guess that the most sensitive services are apache2, php and mysql since they are required for webpage availability. Postfix, mailman and dovecot can be shutdown longer, since waiting a few minutes for them is not critical.

My questions are:

  1. Is there an order in which I need to shutdown services?

    • How do I find those which rely on each other?

    • For instance, I recon it is best to shutdown apache before php or mysql, that way the web server becomes unavailable altogether, instead of potentially displaying odd stuffs to the visitors.

    • What about dovecot, mailman, postfix, bind? Do they rely on mysql? Do they need other services?

  2. What if I want to perform a snapshot?

    • How can I shutdown ALL non critical running services and restart them later? The idea is to minimize as much as possible write access on the disk during the backup.

Edit: the server is hosted somewhere in the world. I can only access it through ssh.

share|improve this question

1 Answer 1

Don't rely on the dependence system, because it may change in future updates.
The correct procedure to follow is to change runlevel and go in Single User Mode with an init sequence (official MAN link). The system will terminate the services in the correct order for you.
Open a virtual terminal (CTRL+ALT+Fn) and gain root privileges with su or sudo su (last preferred). After you are root ("#"), execute:

telinit 1

OR

telinit S

You can also use init directly if telinit fails.
This procedure will terminate any "extra" service to prevent excessive disk access and leave you as the only active user, what you need.
An alternative, longer, procedure is to reboot your system and access the Single User Mode from GRUB with the apposite menu option called Recovery (the Recovery Single User Mode will mount the filesystems with the read only flags enabled, do you'll need to remount them later). After you've done the maintenance or the backup, execute telinit 3 to go back to multi user mode; all registered multi user daemons will be restarted.

Please comment down here if you have more questions and don't forget to press the left UP arrow if I'm of any help.
Have a nice day.

share|improve this answer
1  
Thank you very much for your reply. It is really helpful because I didn't consider the option of changing the run level. Looks like the most elegant way to go : let the system take care of the details. Is it possible to have it fully automatic? I mean, my server is hotsed somewhere in the world. I can only ssh to it or run cron tasks. Obviously, I can't do what you suggest with ssh, but can I change the runlevel from a cron task, and somehow, in single user mode have my backup trigger, and change the run level again? I have to be extra careful: errors (that require manual reboot) cost $80. –  Adeline May 11 at 16:55
    
Cron and the Networking are disabled in S.U.M. because this mode is intended for local maintenance; Ubuntu doesn't natively support what do you want to do. READ "goo.gl/07anmS";. To disable the KILL of a service in S.U.M. execute: 'sudo update-rc.d -f yourservicename remove' and then 'sudo update-rc.d -f yourservicename start yourstartpriority 1 2 3 5 . stop 0 6 .'; this will start the service in single user mode (if the service supports it!); also follow any README file in the rc directories (they vary). Modify the rc scripts to mount /var so cron can read the spool. Good scripting. :) –  Lorenzo Ancora May 11 at 18:23

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.