]> git.proxmox.com Git - pve-manager.git/blob - bin/vzdump
vzdump: add bash completion support
[pve-manager.git] / bin / vzdump
1 #!/usr/bin/perl -w -T
2
3 use strict;
4 use PVE::SafeSyslog;
5 use PVE::INotify;
6 use PVE::RPCEnvironment;
7 use PVE::CLIHandler;
8 use PVE::API2::VZDump;
9
10 use Data::Dumper; # fixme: remove
11
12 use base qw(PVE::CLIHandler);
13
14 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
15
16 initlog('vzdump');
17
18 die "please run as root\n" if $> != 0;
19
20 PVE::INotify::inotify_init();
21
22 my $rpcenv = PVE::RPCEnvironment->init('cli');
23
24 $rpcenv->init_request();
25 $rpcenv->set_language($ENV{LANG});
26 $rpcenv->set_user('root@pam');
27
28
29 my $cmddef = [ 'PVE::API2::VZDump', 'vzdump', ['vmid'], undef,
30 sub {
31 my $upid = shift;
32 exit(0) if $upid eq 'OK';
33 my $status = PVE::Tools::upid_read_status($upid);
34 exit($status eq 'OK' ? 0 : -1);
35 }];
36
37 push @ARGV, 'help' if !scalar(@ARGV);
38
39 PVE::CLIHandler::handle_simple_cmd($cmddef, \@ARGV, undef, $0);
40
41 exit 0;
42
43 __END__
44
45 =head1 NAME
46
47 vzdump - backup utility for virtual machine
48
49 =head1 SYNOPSIS
50
51 =include synopsis
52
53 =head1 DESCRIPTION
54
55 vzdump is an utility to make consistent snapshots of running virtual
56 machines (VMs). It basically creates an archive of the VM private area,
57 which also includes the VM configuration files. vzdump currently
58 supports OpenVZ and QemuServer VMs.
59
60 There are several ways to provide consistency (option C<mode>):
61
62 =over 2
63
64 =item C<stop> mode
65
66 Stop the VM during backup. This results in a very long downtime.
67
68 =item C<suspend> mode
69
70 For OpenVZ, this mode uses rsync to copy the VM to a temporary
71 location (see option --tmpdir). Then the VM is suspended and a second
72 rsync copies changed files. After that, the VM is started (resume)
73 again. This results in a minimal downtime, but needs additional space
74 to hold the VM copy.
75
76 For QemuServer, this mode work like C<stop> mode, but uses
77 suspend/resume instead of stop/start.
78
79 =item C<snapshot> mode
80
81 This mode uses LVM2 snapshots. There is no downtime, but snapshot mode
82 needs LVM2 and some free space on the corresponding volume group to
83 create the LVM snapshot.
84
85 =back
86
87 =head1 BACKUP FILE NAMES
88
89 Newer version of vzdump encodes the virtual machine type and the
90 backup time into the filename, for example
91
92 vzdump-openvz-105-2009_10_09-11_04_43.tar
93
94 That way it is possible to store several backup into the same
95 directory. The parameter C<maxfiles> can be used to specify the maximal
96 number of backups to keep.
97
98 =head1 RESTORE
99
100 The resulting archive files can be restored with the following programs.
101
102 =over 1
103
104 =item vzrestore: OpenVZ restore utility
105
106 =item qmrestore: QemuServer restore utility
107
108 =back
109
110 For details see the corresponding manual pages.
111
112 =head1 CONFIGURATION
113
114 Global configuration is stored in /etc/vzdump.conf.
115
116 tmpdir: DIR
117 dumpdir: DIR
118 storage: STORAGE_ID
119 mode: snapshot|suspend|stop
120 bwlimit: KBPS
121 ionize: PRI
122 lockwait: MINUTES
123 stopwait: MINUTES
124 size: MB
125 maxfiles: N
126 script: FILENAME
127 exclude-path: PATHLIST
128
129 =head1 HOOK SCRIPT
130
131 You can specify a hook script with option C<--script>. This script is called at various phases of the backup process, with parameters accordingly set. You can find an example in the documentation directory (C<vzdump-hook-script.pl>).
132
133 =head1 EXCLUSIONS (OpenVZ only)
134
135 vzdump skips the following files wit option --stdexcludes
136
137 /var/log/.+
138 /tmp/.+
139 /var/tmp/.+
140 /var/run/.+pid
141
142 You can manually specify exclude paths, for example:
143
144 # vzdump 777 --exclude-path C</tmp/.+> --exclude-path C</var/tmp/.+>
145
146 (only excludes tmp directories)
147
148 Configuration files are also stored inside the backup archive (/etc/vzdump), and will be correctly restored.
149
150 =head1 LIMITATIONS
151
152 VZDump does not save ACLs.
153
154 =head1 EXAMPLES
155
156 Simply dump VM 777 - no snapshot, just archive the VM private area and configuration files to the default dump directory (usually /vz/dump/).
157
158 # vzdump 777
159
160 Use rsync and suspend/resume to create an snapshot (minimal downtime).
161
162 # vzdump 777 --mode suspend
163
164 Backup all VMs and send notification mails to root and admin.
165
166 # vzdump --all --mode suspend --mailto root --mailto admin
167
168 Use LVM2 to create snapshots (no downtime).
169
170 # vzdump 777 --dumpdir /mnt/backup --mode snapshot
171
172 Backup more than one VM (selectively)
173
174 # vzdump 101 102 103 --mailto root
175
176 Backup all VMs excluding VM 101 and 102
177
178 # vzdump --mode suspend --exclude 101,102
179
180 Restore an OpenVZ machine to VM 600
181
182 # vzrestore /mnt/backup/vzdump-openvz-777.tar 600
183
184 Restore an Qemu/KVM machine to VM 601
185
186 # qmrestore /mnt/backup/vzdump-qemu-888.vma 601
187
188 Clone an existing container 101 to container 300 using pipes
189
190 # vzdump 101 --stdout|vzrestore - 300
191
192 =head1 SEE ALSO
193
194 vzrestore(1) qmrestore(1)
195
196 =include pve_copyright