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