-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine-commands-for-later-execution-auto-restore-backup-configurations.html
127 lines (108 loc) · 7.77 KB
/
define-commands-for-later-execution-auto-restore-backup-configurations.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Define commands for later execution / auto-restore backup configurations - kb.haeringer.org</title>
<link href="http://fonts.googleapis.com/css?family=Arimo:400,700|Inika" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/theme/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/theme/pastie.css" />
<link href="/" type="application/atom+xml" rel="alternate" title="kb.haeringer.org Atom Feed" />
</head>
<body>
<div class="container">
<div class="row">
<div class="span10">
<div id="content">
<div class="header">
<h1>Define commands for later execution / auto-restore backup configurations</h1>
</br>
</div>
<p class="meta"><small><span><a href="/author/ben/">ben</a> - </span><span>Di 20 Juli 2010</span> - <span class="tags"><a href="/tag/ASA/">ASA</a>, <a href="/tag/Backup/">Backup</a>, <a href="/tag/Cisco IOS/">Cisco IOS</a></span></small></p>
<div class="entry-content">
<p>Sometimes it can be critical to configure a remote device, e.g. if you
have to configure something on the network interface over which you
reach the machine. But there are ways to ensure that you won't be locked
out forever in case something goes wrong.</p>
<p><strong>On Linux</strong>, there's the commmand "at". You can define commands for
later execution with it, without setting up a cron job. For example, if
you have to change something on /etc/network/interfaces, you only need
to make a backup of the previous configuration and tell the system to
copy back the backup at a specific time.</p>
<p>Before configuring anything, make a backup:</p>
<div class="highlight"><pre><span class="n">cp</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">network</span><span class="o">/</span><span class="n">interfaces</span> <span class="o">/</span><span class="n">etc</span><span class="o">/</span><span class="n">network</span><span class="o">/</span><span class="n">interfaces</span><span class="p">.</span><span class="n">bak</span>
</pre></div>
<p>Define the "rescue jobs" with <code>at</code> (if "at" is unknown, install via
<code>apt-get install at</code>):<br />
<!--more--></p>
<div class="highlight"><pre><span class="n">echo</span> <span class="s">"cp /etc/network/interfaces.bak /etc/network/interfaces"</span> <span class="o">|</span> <span class="n">at</span> <span class="mi">11</span><span class="o">:</span><span class="mi">30</span>
<span class="n">echo</span> <span class="s">"ifdown eth0"</span> <span class="o">|</span> <span class="n">at</span> <span class="mi">11</span><span class="o">:</span><span class="mi">31</span>
<span class="n">echo</span> <span class="s">"ifup eth0"</span> <span class="o">|</span> <span class="n">at</span> <span class="mi">11</span><span class="o">:</span><span class="mi">32</span>
<span class="cp"># or alternatively:</span>
<span class="n">echo</span> <span class="s">"ifup eth0"</span> <span class="o">|</span> <span class="n">at</span> <span class="n">now</span> <span class="o">+</span> <span class="mi">1</span><span class="n">min</span>
</pre></div>
<p>Show your open jobs with <code>atq</code>:</p>
<div class="highlight"><pre><span class="n">root</span><span class="err">@</span><span class="n">SERVER</span><span class="o">:/</span><span class="n">home</span><span class="o">/</span><span class="n">ben</span><span class="err">#</span> <span class="n">atq</span>
<span class="mi">1</span> <span class="n">Tue</span> <span class="n">Sep</span> <span class="mi">20</span> <span class="mi">11</span><span class="o">:</span><span class="mi">30</span><span class="o">:</span><span class="mo">00</span> <span class="mi">2010</span> <span class="n">a</span> <span class="n">root</span>
<span class="mi">2</span> <span class="n">Tue</span> <span class="n">Sep</span> <span class="mi">20</span> <span class="mi">11</span><span class="o">:</span><span class="mi">31</span><span class="o">:</span><span class="mo">00</span> <span class="mi">2010</span> <span class="n">a</span> <span class="n">root</span>
<span class="mi">3</span> <span class="n">Tue</span> <span class="n">Sep</span> <span class="mi">20</span> <span class="mi">11</span><span class="o">:</span><span class="mi">32</span><span class="o">:</span><span class="mo">00</span> <span class="mi">2010</span> <span class="n">a</span> <span class="n">root</span>
</pre></div>
<p>Delete jobs with <code>atrm</code>:</p>
<div class="highlight"><pre><span class="n">atrm</span> <span class="mi">2</span>
</pre></div>
<p>Now you can safely configure the interface, and in case anything goes
wrong, you can be pretty sure that you will be able to reach the system
again at 11:31 ;)</p>
<p><strong>On Cisco networking devices</strong> for example, there's also a way to
restore the original configuration, but things are a little different:
As you probably know, commands have an immediate effect on the systems
operation, unlike Linux where processes have to be restarted after
changing their configuration. But the running-config needs to be saved
as startup-config, otherwise any configurations will be lost after a
reboot. You can use this fact to restore the previous configuration in
case something went wrong and you're not able to reach a remote device
anymore.</p>
<p>Simply issue the command "reload in \<minutes>" to tell the device that
it should reload in your desired amount of time.</p>
<div class="highlight"><pre><span class="n">R3</span><span class="err">#</span> <span class="n">reload</span> <span class="n">in</span> <span class="mi">15</span>
<span class="n">Reload</span> <span class="n">scheduled</span> <span class="n">in</span> <span class="mi">15</span> <span class="n">minutes</span>
<span class="n">Proceed</span> <span class="n">with</span> <span class="n">reload</span><span class="o">?</span> <span class="p">[</span><span class="n">confirm</span><span class="p">]</span>
<span class="n">R3</span><span class="err">#</span>
</pre></div>
<p>You will get a warning every five minutes or so that the device is going
to reboot. When you have finished your configuration successfully, don't
forget to cancel the reload!</p>
<div class="highlight"><pre><span class="n">R3</span><span class="err">#</span> <span class="n">reload</span> <span class="n">cancel</span>
<span class="n">R3</span><span class="err">#</span>
<span class="o">***</span>
<span class="o">***</span> <span class="o">---</span> <span class="n">SHUTDOWN</span> <span class="n">ABORTED</span> <span class="o">---</span>
<span class="o">***</span>
<span class="n">R3</span><span class="err">#</span>
</pre></div>
</div><!-- /.entry-content -->
</div>
</div>
<div class="span2">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header">Blog</li>
<!-- <li ><a href="">Home</a></li> -->
<li ><a href="index.html">Home</a></li>
<li ><a href="/tags/">Tags</a></li>
<li ><a href="/archives/">Archive</a></li>
<li class="nav-header">Pages</li>
<li><a href="/pages/about.html">About</a></li>
</ul>
</div><!-- /#menu -->
</div>
</div>
<hr />
<div class="row">
<div class="span12">
<div id="about">
<p>Proudly powered by <a href="http://twitter.github.com/bootstrap/">bootstrap</a>, <a href="http://docs.notmyidea.org/alexis/pelican/">pelican</a>, <a href="http://python.org">python</a> and <a href="http://www.julo.ch/about/">Alex</a></p>
</div><!-- /#about -->
</div><!-- /#contentinfo -->
</div>
</div>
</body>
</html>