Getting errors while making backup of whole centos with tar
Solution 1:
Note that your tar
command is completing successfully; it's just complaining about the socket entries. Tiffany is suggesting a mechanism for filtering out those particular error messages, although tar
will still exit with an error code.
You could also feed a list of sockets to tar
's -X
option to have them excluded from the backup, e.g:
# 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
The advantage to this technique is that it makes tar
's exit code more useful (that is, you can use the exit code to decide whether or not the backup completed successfully).
You could also shorten your command line by replacing your other --exclude
options with a single -X
(aka --exclude-from
) and simply listing them in a file.
Solution 2:
The fact is tar is successful, but prints out warning that those socket files are ignored
GNU tar actually provides an option to suppress warnings. You could ignore the "socket ignored" errors using the below command which avoids running a find command that could take a long time to complete.
tar --warning='no-file-ignored' -cpzf backup_name.tar.gz /folder_to_backup
This links has more details
Solution 3:
Sockets are zero level files that are used by daemon processes to communicate with each other. They are created and destroyed as necessary when the daemons start and stop. They can safely be ignored.
You can always get rid of them with tar <my_options> 2> >(grep -v 'socket ignored' >&2)