使用tar备份整个centos时出错


10

我正在尝试此命令

tar cvpzf /TEMP_BACKUPS/backup.tgz --exclude=/proc --exclude=/lost+found  --exclude=/tmp --exclude=/TEMP_BACKUPS --exclude=/mnt --exclude=/sys / > /TEMP_BACKUPS/mylog.txt

而且我收到此错误。我已经试过两次

tar: Removing leading `/' from member names
tar: /dev/log: socket ignored
tar: Removing leading `/' from hard link targets
tar: /selinux/policy: Cannot open: Invalid argument
tar: /var/spool/postfix/public/flush: socket ignored
tar: /var/spool/postfix/public/cleanup: socket ignored
tar: /var/spool/postfix/public/showq: socket ignored
tar: /var/spool/postfix/private/defer: socket ignored
tar: /var/spool/postfix/private/virtual: socket ignored
tar: /var/spool/postfix/private/proxywrite: socket ignored
tar: /var/spool/postfix/private/verify: socket ignored
tar: /var/spool/postfix/private/anvil: socket ignored
tar: /var/spool/postfix/private/lmtp: socket ignored
tar: /var/spool/postfix/private/bounce: socket ignored
tar: /var/spool/postfix/private/relay: socket ignored
tar: /var/spool/postfix/private/scache: socket ignored
tar: /var/spool/postfix/private/retry: socket ignored
tar: /var/spool/postfix/private/error: socket ignored
tar: /var/spool/postfix/private/rewrite: socket ignored
tar: /var/spool/postfix/private/tlsmgr: socket ignored
tar: /var/spool/postfix/private/local: socket ignored
tar: /var/spool/postfix/private/discard: socket ignored
tar: /var/spool/postfix/private/trace: socket ignored
tar: /var/spool/postfix/private/smtp: socket ignored
tar: /var/spool/postfix/private/proxymap: socket ignored
tar: /var/lib/mysql/mysql.sock: socket ignored
tar: /var/www/html/run/wsgi.1458.0.1.sock: socket ignored
tar: /var/www/html/run/wsgi.4861.1.1.sock: socket ignored
tar: /var/www/html/run/wsgi.1178.0.1.sock: socket ignored
tar: /var/www/html/run/wsgi.1179.0.1.sock: socket ignored
tar: /var/run/dbus/system_bus_socket: socket ignored
tar: /var/run/abrt/abrt.socket: socket ignored
tar: /var/run/rpcbind.sock: socket ignored
tar: /var/run/portreserve/socket: socket ignored
tar: /var/run/nscd/socket: socket ignored
tar: Exiting with failure status due to previous errors

我需要怎么做才能完全备份

Answers:


14

请注意,您的tar命令已成功完成;它只是在抱怨套接字条目。Tiffany建议使用一种机制来过滤掉那些特定的错误消息,尽管tar仍然会以错误代码退出。

您还可以向tar-X选项提供套接字列表,以将其从备份中排除,例如:

# find / -type s -print > /tmp/sockets-to-exclude
# tar cvpzf /TEMP_BACKUPS/backup.tgz -X /tmp/sockets-to-exclude \
  --exclude=/proc --exclude=/lost+found  --exclude=/tmp \
  --exclude=/TEMP_BACKUPS --exclude=/mnt --exclude=/sys / > /TEMP_BACKUPS/mylog.txt

该技术的优点在于,它使tar的退出代码更加有用(也就是说,您可以使用退出代码来确定备份是否成功完成)。

您还可以通过用--exclude一个-X(aka --exclude-from)替换其他选项并将它们简单地列出在文件中来缩短命令行。


/run也应该排除在外吗?
ar2015 '16

的标准错误find / -type s -print > /tmp/sockets-to-exclude应重定向到某处(例如/dev/null),否则会发现抱怨说在搜索过程中创建的某些文件不存在。
哈维尔·阿里亚斯

16

事实是tar成功,但打印出警告,指出那些套接字文件已被忽略

GNU tar实际上提供了抑制警告的选项。您可以使用以下命令忽略“套接字被忽略”错误,这样可以避免运行可能需要很长时间才能完成的find命令。

tar --warning='no-file-ignored' -cpzf  backup_name.tar.gz  /folder_to_backup

此链接有更多详细信息


9

套接字是零级文件,守护进程使用该套接字相互通信。当守护程序启动和停止时,将根据需要创建和销毁它们。可以放心地忽略它们。

您可以随时使用它们来摆脱它们 tar <my_options> 2> >(grep -v 'socket ignored' >&2)


我不明白,您的意思是通过忽略套接字,我的tar可以正常运行而不会退出
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.