tar Archives - Justin Silver https://www.justinsilver.com/tag/tar/ Technology, Travel, and Pictures Wed, 27 Apr 2016 20:19:21 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.1 https://www.justinsilver.com/wp-content/uploads/2013/06/cropped-apple-touch-icon-160x160.png tar Archives - Justin Silver https://www.justinsilver.com/tag/tar/ 32 32 MySQL / MariaDB Backup & Archive Script https://www.justinsilver.com/technology/linux/mysql-mariadb-backup-archive-script/?utm_source=rss&utm_medium=rss&utm_campaign=mysql-mariadb-backup-archive-script https://www.justinsilver.com/technology/linux/mysql-mariadb-backup-archive-script/#respond Fri, 18 Mar 2016 00:04:28 +0000 http://www.justinsilver.com/?p=4021 I am using MariaDB – the open source version of MySQL – and wanted an easy way to backup my databases on a regular schedule without having to do anything when I created or...

The post MySQL / MariaDB Backup & Archive Script appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

I am using MariaDB – the open source version of MySQL – and wanted an easy way to backup my databases on a regular schedule without having to do anything when I created or dropped a database. MariaDB is a drop in replacement for MySQL, so this script should work as is. I put together this base script that will use the show databases command to iterate over each database so that it can be passed to mysqldump. The nice command is used to lower the impact to your regular server work.

Once exported the resulting SQL files are compressed into an archive using tar with bzip2 compression, which saves quite a bit of space over gzip from my tests with this kind of data. After the archive is created the source SQL files are deleted (again using nice) and finally anything in the directory older than the specified archive days value will be deleted.

You will need to create a file called /etc/sysconfig/dbbackup that stores the USERNAME and PASSWORD parameters for the script.

#/bin/bash
#
# MySQL/MariaDB backup script
# Justin Silver
# http://www.justinsilver.com
#
# Use cron to schedule this script to run as frequently as you want.
###################################################################################

# Set properties in this file
SYSCONFIG="/etc/sysconfig/dbbackup"

# User with SELECT, SHOW VIEW, EVENT, and TRIGGER, or... root
#USERNAME="USERNAME"
#PASSWORD="PASSWORD"

# Archive path
ARCHIVE_PATH="/var/backups"

# Archive filename
ARCHIVE_FILE="databases_`date +%F_%H-%M-%S`.tbz2"

# Archives older than this will be deleted
ARCHIVE_DAYS="15"

# Set or override config variables here
if [ -f $SYSCONFIG ]; then
    source $SYSCONFIG
fi

if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
    echo "You must set USERNAME and PASSWORD in $SYSCONFIG";
    exit
fi

# Change working directory
cd $ARCHIVE_PATH

# Get all of the databases
for database in `mysql -u $USERNAME -p"$PASSWORD" -Bse 'show databases'`; do

        # Skip ones we don't want to back up
        if [ "performance_schema" == "$database" ]; then continue; fi
        if [ "information_schema" == "$database" ]; then continue; fi

        # Use Nice to dump the database
        nice mysqldump -u $USERNAME -p"$PASSWORD" --events $database > $database.sql

done

# Use Nice to create a tar compressed with bzip2
nice tar -cjf $ARCHIVE_FILE *.sql

# Remove the SQL files
nice rm -rf *.sql

# Remove old archive files
nice find . -mtime +$ARCHIVE_DAYS -exec rm {} \;

The post MySQL / MariaDB Backup & Archive Script appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/linux/mysql-mariadb-backup-archive-script/feed/ 0
Extract a tar.xz file on CentOS and RedHat https://www.justinsilver.com/technology/linux/extract-tar-xz-file-centos-redhat/?utm_source=rss&utm_medium=rss&utm_campaign=extract-tar-xz-file-centos-redhat https://www.justinsilver.com/technology/linux/extract-tar-xz-file-centos-redhat/#comments Thu, 30 Oct 2014 00:17:53 +0000 http://justinsilver.com/?p=3789 This guide will show you how to extract a tar.xz file on CentOS or RedHat, and probably other flavors of Linux as well. Traditionally compressed archive files are distributed on Linux systems as tar.gz...

The post Extract a tar.xz file on CentOS and RedHat appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

This guide will show you how to extract a tar.xz file on CentOS or RedHat, and probably other flavors of Linux as well. Traditionally compressed archive files are distributed on Linux systems as tar.gz files which use gzip for compression. Extracting them is as simple as passing xzf to tar.

tar -xvf filename.tar.gz

If you try the same thing using a tar.xz file, you’ll find that it doesn’t work.

tar -xzf filename.tar.xz
gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error exit delayed from previous errors

On newer versions of tar, you can simply replace the z with a J to use the correct (de)compression library, but if you have version 1.15.1 or earlier, you’ll find that this doesn’t work either. Note that this is a capital “J” and not a lowercase “j” which would be used to specify bzip2 compression.

tar -xJf gnutls.tar.xz
tar: invalid option -- J
Try `tar --help' or `tar --usage' for more information.

Getting around this is as simple as using the xz binary to first decompress the file, and then tar to extract it. If you don’t already have it, you can install xz using yum.

yum -y install xz
unxz filename.tar.xz
tar -xf filename.tar

The post Extract a tar.xz file on CentOS and RedHat appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/linux/extract-tar-xz-file-centos-redhat/feed/ 7