{"id":357,"date":"2012-05-28T15:08:34","date_gmt":"2012-05-28T14:08:34","guid":{"rendered":"http:\/\/www.jbahillo.com\/?page_id=357"},"modified":"2013-02-21T19:26:20","modified_gmt":"2013-02-21T18:26:20","slug":"bash-mysql-backup-v-1-2","status":"publish","type":"page","link":"https:\/\/www.jbahillo.com\/?page_id=357","title":{"rendered":"[Bash] Mysql Backup v 1.2"},"content":{"rendered":"<p>Este script realiza copias de la base de datos indicada<\/p>\n<pre class=\"brush: bash; gutter: true; first-line: 1; highlight: []; html-script: false\">#!\/bin\/bash\n####################SECCION DE CONFIGURACION###################3\nDB_NAME=db_name\nDB_USER=db_user\nDB_PASS=db_pass\nDB_HOST=db_host\nADMIN_EMAIL= tu.direccion@de.correo.com\nDOMINIO=tu.dominio.com\nMAIL_DEBUG=1 \nBACKUP_DIR=\/ruta\/donde\/se\/almacenaran\/los\/backups\n############################################################\n\nLAST_FILE=`ls -1t $BACKUP_DIR | head -n1`\n\n#fichero temporal\nmysqldump --user=${DB_USER} --password=${DB_PASS} --host=${DB_HOST} ${DB_NAME}  | bzip2 -c &gt; \/tmp\/db-$(date +%Y%m%d).sql.bz2\n\nif [ &quot;$?&quot; -ne &quot;0&quot; ]; then\n        if [ $MAIL_DEBUG = 0 ]; then\n\t\techo -e &quot;\\nmysqldump failed!&quot;\n\t\texit 1\n\telse\n\t\techo &quot;Ha habido un problema al ejecutar el backup de la base de datos. El comando mysqldump ha fallado&quot; | mail -s &quot;Backup de $DOMINIO&quot; $ADMIN_EMAIL\n\n        \texit 1\n\tfi\nfi\n\ntar -cjf \/tmp\/db-$(date +%Y%m%d).tar.bz2 \/tmp\/db-$(date +%Y%m%d).sql.bz2\nif [ &quot;$?&quot; -ne &quot;0&quot; ]; then\n\tif [ $MAIL_DEBUG = 0 ]; then\t\n\t\techo -ne &quot;tarball creation failed!\\\\n&quot;\n       \t\texit 1\n\telse \n\t\techo &quot;Ha habido un problema al comprimir el backup de la base de datos. El comando tar ha fallado&quot; | mail -s &quot;Backup de $DOMINIO&quot; $ADMIN_EMAIL\n\tfi\nfi\n\nTEMP_FILE=\/tmp\/db-$(date +%Y%m%d).tar.bz2\n######################comprobacion de tama\u00f1o#######################################\n\nif [ `du -h $TEMP_FILE | cut -f1` == `du -h $BACKUP_DIR\/$LAST_FILE | cut -f1` ]; then \n\tif [ $MAIL_DEBUG = 0 ]; then\n\t\techo &quot; No se hace nada, no ha habido cambios&quot;\n\telse\n\t\techo &quot;No se ha completado el backup, ya que no ha habido cambios&quot; | mail -s &quot;Backup de $DOMINIO&quot; $ADMIN_EMAIL\n\tfi\t\nelse\n\tif [ $MAIL_DEBUG = 0 ]; then\n\t\techo &quot;Ha habido cambios, procedemos a almacenar el backup&quot;\n\tfi\t\nmv \/tmp\/db-$(date +%Y%m%d).tar.bz2 $BACKUP_DIR\necho &quot;&quot; | mutt -a  $BACKUP_DIR\/db-$(date +%Y%m%d).tar.bz2 -s &quot;Backup de $DOMINIO&quot; $ADMIN_EMAIL\nfi\n\ncontadortotal=0\nfor e in $( ls .\/ | nl | cut -f2 )\ndo\nlet contadortotal=$contadortotal+1\ndone\nlet contadortotal=$contadortotal-30\n\ncontadorparcial=0\n\nfor e in $( ls -tr .\/ | nl | cut -f2 )\ndo\nlet contadorparcial=$contadorparcial+1\nif [ $contadorparcial -lt $contadortotal ] ; then\nrm $e\nfi\ndone\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Este script realiza copias de la base de datos indicada #!\/bin\/bash ####################SECCION DE CONFIGURACION###################3 DB_NAME=db_name DB_USER=db_user DB_PASS=db_pass DB_HOST=db_host ADMIN_EMAIL= tu.direccion@de.correo.com DOMINIO=tu.dominio.com MAIL_DEBUG=1 BACKUP_DIR=\/ruta\/donde\/se\/almacenaran\/los\/backups ############################################################ LAST_FILE=`ls -1t $BACKUP_DIR | head -n1` #fichero temporal mysqldump &#8211;user=${DB_USER} &#8211;password=${DB_PASS} &#8211;host=${DB_HOST} ${DB_NAME} | bzip2 -c&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"https:\/\/www.jbahillo.com\/?page_id=357\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":21,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"ep_exclude_from_search":false,"footnotes":""},"class_list":["post-357","page","type-page","status-publish","hentry"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Script en Bash que realiza backups de bases de datos MySQL\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"keywords\" content=\"bash,script,wp_backup,mysql\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.jbahillo.com\/?page_id=357\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"es_ES\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Javier Bahillo | Blog de un Administrador de Sistemas\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Bash Mysql Backup v1.1 | Javier Bahillo\" \/>\n\t\t<meta property=\"og:description\" content=\"Script en Bash que realiza backups de bases de datos MySQL\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.jbahillo.com\/?page_id=357\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2012-05-28T14:08:34+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2013-02-21T18:26:20+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Bash Mysql Backup v1.1 | Javier Bahillo\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Script en Bash que realiza backups de bases de datos MySQL\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/?page_id=357#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jbahillo.com#listItem\",\"position\":1,\"name\":\"Inicio\",\"item\":\"https:\\\/\\\/www.jbahillo.com\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/?page_id=357#listItem\",\"name\":\"[Bash] Mysql Backup v 1.2\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/?page_id=357#listItem\",\"position\":2,\"name\":\"[Bash] Mysql Backup v 1.2\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.jbahillo.com#listItem\",\"name\":\"Inicio\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/#organization\",\"name\":\"Javier Bahillo\",\"description\":\"Blog de un Administrador de Sistemas\",\"url\":\"https:\\\/\\\/www.jbahillo.com\\\/\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/?page_id=357#webpage\",\"url\":\"https:\\\/\\\/www.jbahillo.com\\\/?page_id=357\",\"name\":\"Bash Mysql Backup v1.1 | Javier Bahillo\",\"description\":\"Script en Bash que realiza backups de bases de datos MySQL\",\"inLanguage\":\"es-ES\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/?page_id=357#breadcrumblist\"},\"datePublished\":\"2012-05-28T15:08:34+01:00\",\"dateModified\":\"2013-02-21T19:26:20+01:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/#website\",\"url\":\"https:\\\/\\\/www.jbahillo.com\\\/\",\"name\":\"Javier Bahillo\",\"description\":\"Blog de un Administrador de Sistemas\",\"inLanguage\":\"es-ES\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.jbahillo.com\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Bash Mysql Backup v1.1 | Javier Bahillo","description":"Script en Bash que realiza backups de bases de datos MySQL","canonical_url":"https:\/\/www.jbahillo.com\/?page_id=357","robots":"max-image-preview:large","keywords":"bash,script,wp_backup,mysql","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BreadcrumbList","@id":"https:\/\/www.jbahillo.com\/?page_id=357#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.jbahillo.com#listItem","position":1,"name":"Inicio","item":"https:\/\/www.jbahillo.com","nextItem":{"@type":"ListItem","@id":"https:\/\/www.jbahillo.com\/?page_id=357#listItem","name":"[Bash] Mysql Backup v 1.2"}},{"@type":"ListItem","@id":"https:\/\/www.jbahillo.com\/?page_id=357#listItem","position":2,"name":"[Bash] Mysql Backup v 1.2","previousItem":{"@type":"ListItem","@id":"https:\/\/www.jbahillo.com#listItem","name":"Inicio"}}]},{"@type":"Organization","@id":"https:\/\/www.jbahillo.com\/#organization","name":"Javier Bahillo","description":"Blog de un Administrador de Sistemas","url":"https:\/\/www.jbahillo.com\/"},{"@type":"WebPage","@id":"https:\/\/www.jbahillo.com\/?page_id=357#webpage","url":"https:\/\/www.jbahillo.com\/?page_id=357","name":"Bash Mysql Backup v1.1 | Javier Bahillo","description":"Script en Bash que realiza backups de bases de datos MySQL","inLanguage":"es-ES","isPartOf":{"@id":"https:\/\/www.jbahillo.com\/#website"},"breadcrumb":{"@id":"https:\/\/www.jbahillo.com\/?page_id=357#breadcrumblist"},"datePublished":"2012-05-28T15:08:34+01:00","dateModified":"2013-02-21T19:26:20+01:00"},{"@type":"WebSite","@id":"https:\/\/www.jbahillo.com\/#website","url":"https:\/\/www.jbahillo.com\/","name":"Javier Bahillo","description":"Blog de un Administrador de Sistemas","inLanguage":"es-ES","publisher":{"@id":"https:\/\/www.jbahillo.com\/#organization"}}]},"og:locale":"es_ES","og:site_name":"Javier Bahillo | Blog de un Administrador de Sistemas","og:type":"article","og:title":"Bash Mysql Backup v1.1 | Javier Bahillo","og:description":"Script en Bash que realiza backups de bases de datos MySQL","og:url":"https:\/\/www.jbahillo.com\/?page_id=357","article:published_time":"2012-05-28T14:08:34+00:00","article:modified_time":"2013-02-21T18:26:20+00:00","twitter:card":"summary","twitter:title":"Bash Mysql Backup v1.1 | Javier Bahillo","twitter:description":"Script en Bash que realiza backups de bases de datos MySQL"},"aioseo_meta_data":{"post_id":"357","title":"Bash Mysql Backup v1.1 | #site_title","description":"Script en Bash que realiza backups de bases de datos MySQL","keywords":[{"label":"bash","value":"bash"},{"label":"script","value":"script"},{"label":"wp_backup","value":"wp_backup"},{"label":"MySQL","value":"MySQL"}],"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[],"defaultGraph":"","defaultPostTypeGraph":""},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-04-23 00:43:21","updated":"2025-06-03 23:08:31","seo_analyzer_scan_date":null},"jetpack_shortlink":"https:\/\/wp.me\/P74T96-5L","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/pages\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":8,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/pages\/357\/revisions"}],"predecessor-version":[{"id":564,"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=\/wp\/v2\/pages\/357\/revisions\/564"}],"wp:attachment":[{"href":"https:\/\/www.jbahillo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}