备份需要使用root账号。我们执行sudo su - root 切换到root账号下面。 切换目录到根目录 cd / 执行tar命令备份 tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz --one-file-system /
c 创建的意思- create a new backup archive. v 显示详细信息- verbose mode, tar will print what it's doing to the screen. p 保持文件权限- preserves the permissions of the files put in the archive for restoration later. z 使用gzip压缩- compress the backup file with 'gzip' to make it smaller. f <filename> 备份后生成的文件- specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command.
--exclude=/example/path 排除某个路径不去备份- The options following this model instruct tar what directories NOT to backup. We don't want to backup everything since some directories aren't very useful to include. The first exclusion rule directs tar not to back itself up, this is important to avoid errors during the operation.
--one-file-system 的意思是 不包含其他文件系统- Do not include files on a different filesystem
另外一种使用完全手动指定备份目录,不备份的目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
cd / # THIS CD IS IMPORTANT THE FOLLOWING LONG COMMAND IS RUN FROM /