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