1

I'm trying to tar some database files in case something goes sideways during an upgrade. The database has been stopped so there are no sockets:

# systemctl stop rh-mariadb102-mariadb.service
#

When I run tar on the directory of interest, it fails with:

# tar -cvfz mysql.tar.gz mysql/
...
mysql/ibdata1
mysql/aria_log_control
tar: Exiting with failure status due to previous errors

The output does not show any errors. I am running as root and I have access to the files. For example:

# ls -Al mysql/aria_log_control
-rw-rw---- 1 mysql mysql 52 Dec 21 13:35 mysql/aria_log_control

What is the error, and how do I fix it?


The tar(1) man page is kind of brief, but here are the examples it provides:

TAR(1)                           User Commands

NAME
   tar - manual page for tar 1.26

SYNOPSIS
   tar [OPTION...] [FILE]...

DESCRIPTION
   GNU `tar' saves many files together into a single tape or disk archive,
   and can restore individual files from the archive.
   ...

EXAMPLES
   tar -cf archive.tar foo bar
          # Create archive.tar from files foo and bar.

   tar -tvf archive.tar
          # List all files in archive.tar verbosely.

   tar -xf archive.tar
          # Extract all files from archive.tar.

Here is the full output of the command.

# tar -cvfz mysql.tar.gz mysql/
tar: mysql.tar.gz: Cannot stat: No such file or directory
mysql/
mysql/ib_logfile0
mysql/mysql/
mysql/mysql/host.MYI
mysql/mysql/ndb_binlog_index.frm
mysql/mysql/general_log.CSV
mysql/mysql/columns_priv.MYD
mysql/mysql/help_keyword.MYI
mysql/mysql/user.MYD
mysql/mysql/help_category.frm
mysql/mysql/time_zone_transition_type.MYD
mysql/mysql/time_zone_transition.MYI
mysql/mysql/time_zone_name.MYD
mysql/mysql/db.MYD
mysql/mysql/time_zone_transition.MYD
mysql/mysql/time_zone_transition_type.MYI
mysql/mysql/plugin.frm
mysql/mysql/proxies_priv.MYI
mysql/mysql/help_relation.MYI
mysql/mysql/procs_priv.frm
mysql/mysql/user.frm
mysql/mysql/slow_log.frm
mysql/mysql/slow_log.CSV
mysql/mysql/help_topic.frm
mysql/mysql/db.MYI
mysql/mysql/host.MYD
mysql/mysql/help_category.MYD
mysql/mysql/time_zone.MYD
mysql/mysql/time_zone_name.frm
mysql/mysql/procs_priv.MYD
mysql/mysql/time_zone_leap_second.MYD
mysql/mysql/help_category.MYI
mysql/mysql/help_topic.MYD
mysql/mysql/time_zone.MYI
mysql/mysql/event.MYI
mysql/mysql/time_zone_transition.frm
mysql/mysql/plugin.MYD
mysql/mysql/time_zone.frm
mysql/mysql/time_zone_leap_second.frm
mysql/mysql/time_zone_transition_type.frm
mysql/mysql/plugin.MYI
mysql/mysql/procs_priv.MYI
mysql/mysql/proxies_priv.frm
mysql/mysql/proc.MYI
mysql/mysql/time_zone_name.MYI
mysql/mysql/tables_priv.MYD
mysql/mysql/user.MYI
mysql/mysql/help_relation.MYD
mysql/mysql/event.MYD
mysql/mysql/host.frm
mysql/mysql/ndb_binlog_index.MYD
mysql/mysql/time_zone_leap_second.MYI
mysql/mysql/servers.MYD
mysql/mysql/general_log.CSM
mysql/mysql/servers.frm
mysql/mysql/db.frm
mysql/mysql/func.MYD
mysql/mysql/slow_log.CSM
mysql/mysql/help_topic.MYI
mysql/mysql/proxies_priv.MYD
mysql/mysql/proc.frm
mysql/mysql/tables_priv.frm
mysql/mysql/ndb_binlog_index.MYI
mysql/mysql/func.MYI
mysql/mysql/columns_priv.frm
mysql/mysql/general_log.frm
mysql/mysql/columns_priv.MYI
mysql/mysql/tables_priv.MYI
mysql/mysql/func.frm
mysql/mysql/help_keyword.MYD
mysql/mysql/servers.MYI
mysql/mysql/help_relation.frm
mysql/mysql/help_keyword.frm
mysql/mysql/event.frm
mysql/mysql/proc.MYD
mysql/my_wiki/
mysql/my_wiki/wikicryptopp_uploadstash.MYI
mysql/my_wiki/wikilounge_objectcache.MYI
mysql/my_wiki/wikilounge_user_groups.MYD
mysql/my_wiki/wikicryptopp_revision.frm
mysql/my_wiki/wikicryptopp_page_props.frm
mysql/my_wiki/wikilounge_watchlist.frm
mysql/my_wiki/wikilounge_math.MYI
mysql/my_wiki/wikilounge_langlinks.MYD
mysql/my_wiki/wikicryptopp_archive.MYD
mysql/my_wiki/wikilounge_imagelinks.MYI
mysql/my_wiki/wikicryptopp_msg_resource.MYI
mysql/my_wiki/wikilounge_smw_specialprops.MYI
mysql/my_wiki/wikilounge_imagelinks.MYD
mysql/my_wiki/wikicryptopp_sites.MYD
mysql/my_wiki/wikilounge_site_stats.MYI
mysql/my_wiki/wikilounge_templatelinks.MYD
mysql/my_wiki/wikicryptopp_site_identifiers.frm
mysql/my_wiki/wikicryptopp_watchlist.MYI
mysql/my_wiki/wikicryptopp_searchindex.frm
mysql/my_wiki/wikilounge_revision.MYD
mysql/my_wiki/wikicryptopp_site_stats.MYI
mysql/my_wiki/wikicryptopp_text.MYD
mysql/my_wiki/wikilounge_archive.MYI
mysql/my_wiki/wikicryptopp_recentchanges.MYD
mysql/my_wiki/wikicryptopp_image.frm
mysql/my_wiki/wikicryptopp_site_identifiers.MYD
mysql/my_wiki/wikicryptopp_iwlinks.frm
mysql/my_wiki/wikilounge_transcache.frm
mysql/my_wiki/wikicryptopp_user_former_groups.MYD
mysql/my_wiki/wikilounge_querycache_info.frm
mysql/my_wiki/wikicryptopp_trackbacks.frm
mysql/my_wiki/wikilounge_image.MYD
mysql/my_wiki/wikicryptopp_log_search.frm
mysql/my_wiki/wikicryptopp_objectcache.frm
mysql/my_wiki/wikilounge_langlinks.frm
mysql/my_wiki/wikicryptopp_sites.MYI
mysql/my_wiki/wikicryptopp_pagelinks.MYD
mysql/my_wiki/wikilounge_pagelinks.frm
mysql/my_wiki/wikicryptopp_module_deps.MYD
mysql/my_wiki/wikicryptopp_category.frm
mysql/my_wiki/wikicryptopp_site_stats.frm
mysql/my_wiki/wikicryptopp_templatelinks.MYI
mysql/my_wiki/wikicryptopp_transcache.MYD
mysql/my_wiki/wikicryptopp_searchindex.MYI
mysql/my_wiki/wikilounge_filearchive.frm
mysql/my_wiki/wikicryptopp_text.frm
mysql/my_wiki/wikilounge_smw_attributes.MYD
mysql/my_wiki/wikicryptopp_querycache.MYD
mysql/my_wiki/wikilounge_trackbacks.MYI
mysql/my_wiki/wikicryptopp_user_newtalk.MYD
mysql/my_wiki/wikilounge_objectcache.MYD
mysql/my_wiki/wikilounge_site_stats.MYD
mysql/my_wiki/wikilounge_categorylinks.MYD
mysql/my_wiki/wikicryptopp_watchlist.frm
mysql/my_wiki/wikicryptopp_iwlinks.MYI
mysql/my_wiki/wikilounge_text.MYD
mysql/my_wiki/wikicryptopp_job.MYD
mysql/my_wiki/wikilounge_logging.frm
mysql/my_wiki/wikicryptopp_revision.MYD
mysql/my_wiki/wikilounge_searchindex.MYD
mysql/my_wiki/wikicryptopp_categorylinks.MYI
mysql/my_wiki/wikilounge_revision.MYI
mysql/my_wiki/wikilounge_langlinks.MYI
mysql/my_wiki/wikicryptopp_user.MYI
mysql/my_wiki/wikicryptopp_querycache_info.frm
mysql/my_wiki/wikilounge_imagelinks.frm
mysql/my_wiki/wikicryptopp_page.MYD
mysql/my_wiki/wikicryptopp_trackbacks.MYI
mysql/my_wiki/wikicryptopp_ipblocks.MYI
mysql/my_wiki/wikicryptopp_page.frm
mysql/my_wiki/wikilounge_text.frm
mysql/my_wiki/wikilounge_job.MYD
mysql/my_wiki/wikicryptopp_user_former_groups.frm
mysql/my_wiki/wikilounge_categorylinks.MYI
mysql/my_wiki/wikicryptopp_interwiki.MYD
mysql/my_wiki/wikicryptopp_valid_tag.frm
mysql/my_wiki/wikicryptopp_protected_titles.frm
mysql/my_wiki/wikicryptopp_site_stats.MYD
mysql/my_wiki/wikicryptopp_interwiki.MYI
mysql/my_wiki/wikicryptopp_uploadstash.MYD
mysql/my_wiki/wikilounge_categorylinks.frm
mysql/my_wiki/wikilounge_ipblocks.frm
mysql/my_wiki/wikicryptopp_iwlinks.MYD
mysql/my_wiki/db.opt
mysql/my_wiki/wikilounge_user_newtalk.MYI
mysql/my_wiki/wikicryptopp_module_deps.frm
mysql/my_wiki/wikicryptopp_user.frm
mysql/my_wiki/wikilounge_smw_specialprops.frm
mysql/my_wiki/wikilounge_image.frm
mysql/my_wiki/wikicryptopp_math.MYI
mysql/my_wiki/wikilounge_trackbacks.frm
mysql/my_wiki/wikilounge_filearchive.MYI
mysql/my_wiki/wikicryptopp_archive.frm
mysql/my_wiki/wikilounge_watchlist.MYI
mysql/my_wiki/wikicryptopp_transcache.frm
mysql/my_wiki/wikicryptopp_ipblocks.frm
mysql/my_wiki/wikilounge_smw_relations.MYD
mysql/my_wiki/wikicryptopp_imagelinks.MYD
mysql/my_wiki/wikilounge_page.frm
mysql/my_wiki/wikilounge_transcache.MYI
mysql/my_wiki/wikilounge_templatelinks.frm
mysql/my_wiki/wikilounge_querycache_info.MYI
mysql/my_wiki/wikilounge_oldimage.MYD
mysql/my_wiki/wikilounge_recentchanges.MYD
mysql/my_wiki/wikilounge_archive.frm
mysql/my_wiki/wikilounge_recentchanges.MYI
mysql/my_wiki/wikicryptopp_user.MYD
mysql/my_wiki/wikicryptopp_user_newtalk.frm
mysql/my_wiki/wikilounge_interwiki.frm
mysql/my_wiki/wikicryptopp_change_tag.frm
mysql/my_wiki/wikicryptopp_site_identifiers.MYI
mysql/my_wiki/wikilounge_site_stats.frm
mysql/my_wiki/wikicryptopp_externallinks.frm
mysql/my_wiki/wikicryptopp_filearchive.frm
mysql/my_wiki/wikicryptopp_langlinks.frm
mysql/my_wiki/wikilounge_ipblocks.MYI
mysql/my_wiki/wikilounge_searchindex.frm
mysql/my_wiki/wikilounge_watchlist.MYD
mysql/my_wiki/wikicryptopp_objectcache.MYI
mysql/my_wiki/wikicryptopp_querycache.MYI
mysql/my_wiki/wikilounge_smw_specialprops.MYD
mysql/my_wiki/wikicryptopp_math.MYD
mysql/my_wiki/wikicryptopp_msg_resource.MYD
mysql/my_wiki/wikicryptopp_filearchive.MYI
mysql/my_wiki/wikicryptopp_image.MYI
mysql/my_wiki/wikicryptopp_module_deps.MYI
mysql/my_wiki/wikicryptopp_redirect.frm
mysql/my_wiki/wikilounge_job.frm
mysql/my_wiki/wikicryptopp_querycache.frm
mysql/my_wiki/wikicryptopp_msg_resource.frm
mysql/my_wiki/wikicryptopp_user_groups.MYI
mysql/my_wiki/wikilounge_smw_attributes.frm
mysql/my_wiki/wikicryptopp_categorylinks.MYD
mysql/my_wiki/wikilounge_interwiki.MYD
mysql/my_wiki/wikilounge_objectcache.frm
mysql/my_wiki/wikicryptopp_objectcache.MYD
mysql/my_wiki/wikilounge_logging.MYI
mysql/my_wiki/wikicryptopp_sites.frm
mysql/my_wiki/wikicryptopp_oldimage.MYI
mysql/my_wiki/wikicryptopp_querycachetwo.frm
mysql/my_wiki/wikicryptopp_langlinks.MYI
mysql/my_wiki/wikicryptopp_msg_resource_links.frm
mysql/my_wiki/wikicryptopp_templatelinks.MYD
mysql/my_wiki/wikicryptopp_filearchive.MYD
mysql/my_wiki/wikicryptopp_page_restrictions.frm
mysql/my_wiki/wikilounge_oldimage.frm
mysql/my_wiki/wikilounge_math.frm
mysql/my_wiki/wikilounge_querycache.MYI
mysql/my_wiki/wikilounge_page.MYI
mysql/my_wiki/wikicryptopp_logging.frm
mysql/my_wiki/wikilounge_user_groups.frm
mysql/my_wiki/wikicryptopp_user_groups.frm
mysql/my_wiki/wikilounge_smw_attributes.MYI
mysql/my_wiki/wikicryptopp_external_user.frm
mysql/my_wiki/wikicryptopp_user_groups.MYD
mysql/my_wiki/wikicryptopp_externallinks.MYI
mysql/my_wiki/wikicryptopp_trackbacks.MYD
mysql/my_wiki/wikilounge_interwiki.MYI
mysql/my_wiki/wikilounge_pagelinks.MYI
mysql/my_wiki/wikilounge_revision.frm
mysql/my_wiki/wikicryptopp_user_former_groups.MYI
mysql/my_wiki/wikicryptopp_msg_resource_links.MYD
mysql/my_wiki/wikilounge_user.MYD
mysql/my_wiki/wikilounge_image.MYI
mysql/my_wiki/wikilounge_transcache.MYD
mysql/my_wiki/wikicryptopp_querycache_info.MYI
mysql/my_wiki/wikilounge_recentchanges.frm
mysql/my_wiki/wikicryptopp_imagelinks.MYI
mysql/my_wiki/wikilounge_user_newtalk.frm
mysql/my_wiki/wikicryptopp_pagelinks.frm
mysql/my_wiki/wikicryptopp_imagelinks.frm
mysql/my_wiki/wikicryptopp_transcache.MYI
mysql/my_wiki/wikicryptopp_job.frm
mysql/my_wiki/wikilounge_externallinks.MYI
mysql/my_wiki/wikilounge_querycache.MYD
mysql/my_wiki/wikicryptopp_msg_resource_links.MYI
mysql/my_wiki/wikicryptopp_interwiki.frm
mysql/my_wiki/wikicryptopp_templatelinks.frm
mysql/my_wiki/wikilounge_text.MYI
mysql/my_wiki/wikicryptopp_revision.MYI
mysql/my_wiki/wikicryptopp_querycache_info.MYD
mysql/my_wiki/wikicryptopp_math.frm
mysql/my_wiki/wikicryptopp_updatelog.frm
mysql/my_wiki/wikilounge_smw_relations.MYI
mysql/my_wiki/wikilounge_pagelinks.MYD
mysql/my_wiki/wikilounge_trackbacks.MYD
mysql/my_wiki/wikicryptopp_externallinks.MYD
mysql/my_wiki/wikicryptopp_uploadstash.frm
mysql/my_wiki/wikilounge_user_newtalk.MYD
mysql/my_wiki/wikicryptopp_job.MYI
mysql/my_wiki/wikicryptopp_user_newtalk.MYI
mysql/my_wiki/wikicryptopp_page.MYI
mysql/my_wiki/wikilounge_filearchive.MYD
mysql/my_wiki/wikilounge_user.frm
mysql/my_wiki/wikicryptopp_oldimage.MYD
mysql/my_wiki/wikicryptopp_text.MYI
mysql/my_wiki/wikicryptopp_categorylinks.frm
mysql/my_wiki/wikilounge_externallinks.frm
mysql/my_wiki/wikilounge_smw_relations.frm
mysql/my_wiki/wikilounge_user_groups.MYI
mysql/my_wiki/wikilounge_querycache_info.MYD
mysql/my_wiki/wikicryptopp_pagelinks.MYI
mysql/my_wiki/wikilounge_archive.MYD
mysql/my_wiki/wikicryptopp_searchindex.MYD
mysql/my_wiki/wikilounge_hitcounter.frm
mysql/my_wiki/wikicryptopp_langlinks.MYD
mysql/my_wiki/wikicryptopp_watchlist.MYD
mysql/my_wiki/wikilounge_querycache.frm
mysql/my_wiki/wikicryptopp_recentchanges.MYI
mysql/my_wiki/wikilounge_searchindex.MYI
mysql/my_wiki/wikicryptopp_tag_summary.frm
mysql/my_wiki/wikicryptopp_l10n_cache.frm
mysql/my_wiki/wikilounge_job.MYI
mysql/my_wiki/wikilounge_user.MYI
mysql/my_wiki/wikilounge_page.MYD
mysql/my_wiki/wikicryptopp_user_properties.frm
mysql/my_wiki/wikilounge_templatelinks.MYI
mysql/my_wiki/wikilounge_externallinks.MYD
mysql/my_wiki/wikilounge_logging.MYD
mysql/my_wiki/wikilounge_math.MYD
mysql/my_wiki/wikilounge_ipblocks.MYD
mysql/my_wiki/wikilounge_oldimage.MYI
mysql/my_wiki/wikicryptopp_logging.MYI
mysql/my_wiki/wikicryptopp_ipblocks.MYD
mysql/my_wiki/wikicryptopp_archive.MYI
mysql/my_wiki/wikicryptopp_logging.MYD
mysql/my_wiki/wikicryptopp_oldimage.frm
mysql/my_wiki/wikicryptopp_image.MYD
mysql/my_wiki/wikicryptopp_recentchanges.frm
mysql/performance_schema/
mysql/performance_schema/file_summary_by_event_name.frm
mysql/performance_schema/cond_instances.frm
mysql/performance_schema/setup_consumers.frm
mysql/performance_schema/events_waits_summary_global_by_event_name.frm
mysql/performance_schema/mutex_instances.frm
mysql/performance_schema/setup_timers.frm
mysql/performance_schema/db.opt
mysql/performance_schema/events_waits_current.frm
mysql/performance_schema/events_waits_history.frm
mysql/performance_schema/performance_timers.frm
mysql/performance_schema/threads.frm
mysql/performance_schema/file_summary_by_instance.frm
mysql/performance_schema/events_waits_summary_by_thread_by_event_name.frm
mysql/performance_schema/setup_instruments.frm
mysql/performance_schema/file_instances.frm
mysql/performance_schema/rwlock_instances.frm
mysql/performance_schema/events_waits_history_long.frm
mysql/performance_schema/events_waits_summary_by_instance.frm
mysql/aria_log.00000001
mysql/ib_logfile1
mysql/ibdata1
mysql/aria_log_control
tar: Exiting with failure status due to previous errors
#
2

You have the f switch in the wrong place. It should be tar -cvzf. If you omit the dash, tar cvfz will work. This is touched upon in the man page:

Any number of options not taking arguments can be clustered together after a single dash, e.g. -vkp. Options that take arguments (whether mandatory or optional), can appear at the end of such a cluster, e.g. -vkpf a.tar.

  • Thanks, that solved it. It would have been nice if tar stopped at the actual error or printed it as an error instead of an info item. – user56041 Dec 21 '17 at 21:59
2

From the GNU tar manual website

This old way of writing tar options can surprise even experienced users. For example, the two commands:

tar cfz archive.tar.gz file
tar -cfz archive.tar.gz file

are quite different. The first example uses archive.tar.gz' as the value for optionf' and recognizes the option z'. The second example, however, usesz' as the value for option `f' -- probably not what was intended.

This second example could be corrected in many ways, among which the following are equivalent:

tar -czf archive.tar.gz file
tar -cf archive.tar.gz -z file
tar cf archive.tar.gz -z file
  • Thanks Timothy. Remyabel answered first, so he got the check mark. – user56041 Dec 21 '17 at 21:58
2

tar -cvfz mysql.tar.gz mysql/

tar: mysql.tar.gz: Cannot stat: No such file or directory

That error means tar can't find mysql.tar.gz to add to the archive.

(-)f should be followed by the filename, in this case your command is trying to create an archive named z with mysql.tar.gz & mysql/ in it.

In general the order of most flags doesn't matter, but for specifying the filename you want to create it does.

If you use tar -cvzf mysql.tar.gz mysql/ it should work

  • This is a well known gtar bug in option parsing. Depending on wether there is a dash before the options or not, the pgrogram behaves different. – schily Jun 6 '18 at 16:54
  • @schily, it's not a bug, it's documented in the manual... See e.g. Timothy Martin's answer to this same question. – ilkkachu Jun 7 '18 at 8:41
  • I would call a self noncompliance (case dependent syntax) a bug. Note that these kind of problems with GNU tar are partly caused by the way the CLI conversion for dashless use is done and partly by the unpredictable behavior of GNU getopt_long(). If you find similar non-compliances in star called as tar, you get a virtual beer ;-) – schily Jun 7 '18 at 8:51
1

To answer directly the question you actually posed, the error it's referring to is of course this one, on the first line of your output:

tar: mysql.tar.gz: Cannot stat: No such file or directory

That is, a file of that name was listed to be stored in the archive, so that's what it tried to do. It assumes you want the rest of the files archived anyway, and in any case has no way of knowing you'd like a missing file to be a fatal error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy