Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create back-up script and daily cron job #65

Open
shabiel opened this issue May 12, 2020 · 4 comments
Open

Create back-up script and daily cron job #65

shabiel opened this issue May 12, 2020 · 4 comments

Comments

@shabiel
Copy link
Collaborator

shabiel commented May 12, 2020

Here's a sample. Needs to be improved.

#!/bin/bash

# Switch to home directory
cd

# Delete old backups
rm -rv backup/*

# Make new backup directory
bu_date=$(date +%F)
mkdir -p backup/$bu_date

# Backup default region and r directory to backup directory
$gtm_dist/mupip backup DEFAULT backup/$bu_date
tar --exclude '*.o' -czf backup/$bu_date/r.tgz ./r/

# tar into single file and remove directory
tar czvf backup/${bu_date}.tgz backup/${bu_date}
rm -rv backup/$bu_date
@shabiel
Copy link
Collaborator Author

shabiel commented May 18, 2020

Better script

#!/bin/bash

# Switch to home directory
cd /home/vehu/

# Source variables
. /home/vehu/etc/env

# Delete old backups
echo "Deleting old backups..."
rm -rf backup/*

# Get date for file name
bu_date=$(date +%F)

# Make global backup directory
mkdir -p backup/g

# Backup default region
echo "Creating backup of globals..."
$gtm_dist/mupip backup -BKUPDBJNL=OFF DEFAULT backup/g

# Tar and gzip files
echo "Tarring and gzipping routines and globals..."
tar --exclude '*.o' -cf backup/$bu_date.tar ./r/
tar -rf backup/$bu_date.tar -C ./backup/ ./g
if hash pigz 2>/dev/null; then  # Try pigz to speed up gzip, which is the slowest operation here
    echo "Using pigz to gzip..."
    pigz backup/$bu_date.tar
else
    gzip backup/$bu_date.tar
fi

# Delete dat file directory
echo "Deleting gzipped globals backup..."
rm -r backup/g

# Inform the user of the backup directory and size
echo -n "Backed up to /home/vehu/backup/${bu_date}.tar.gz "
echo "Size: " $(stat --printf="%s" /home/vehu/backup/${bu_date}.tar.gz | numfmt --to=si)

# Print file path for scripts
echo /home/vehu/backup/${bu_date}.tar.gz

@ChristopherEdwards
Copy link
Collaborator

that better script looks good here. the command line arg -BKUPDBJNL=OFF to mupip backup I'm not 100% familiar with off the top of my head, but the general pattern looks good

@ChristopherEdwards
Copy link
Collaborator

only other thing is maybe don't delete the old backup before the new one is taken or at least allow it to have n number on file

@shabiel
Copy link
Collaborator Author

shabiel commented May 19, 2020

Better version

#!/bin/bash

# Exit on error
set -e

# Switch to home directory
cd /home/vehu/

# Source variables
. /home/vehu/etc/env

# Get date for file name
bu_date=$(date +%F)

# Remove today's backup if it exists
rm -f backup/$bu_date.tar.gz

# Make global backup directory, rm old contents just in case
mkdir -p backup/g
rm -f backup/g/*

# Backup default region and turn off journaling
echo "Creating backup of globals..."
$gtm_dist/mupip backup -BKUPDBJNL=OFF DEFAULT backup/g

# Tar and gzip files
echo "Tarring and gzipping routines and globals..."
tar --exclude '*.o' -cf backup/$bu_date.tar ./r/
tar -rf backup/$bu_date.tar -C ./backup/ ./g
if hash pigz 2>/dev/null; then  # Try pigz to speed up gzip, which is the slowest operation here
    echo "Using pigz to gzip..."
    pigz backup/$bu_date.tar
else
    gzip backup/$bu_date.tar
fi

# Delete dat file directory
echo "Deleting gzipped globals backup..."
rm -r backup/g

# Delete old backups
echo "Deleting old backups..."
mkdir backup/tmp
mv backup/$bu_date.tar.gz backup/tmp
rm -f backup/*.tar.gz
mv backup/tmp/$bu_date.tar.gz  backup/
rmdir backup/tmp

# Inform the user of the backup directory and size
echo -n "Backed up to /home/vehu/backup/${bu_date}.tar.gz "
echo "Size: " $(stat --printf="%s" /home/vehu/backup/${bu_date}.tar.gz | numfmt --to=si)

# Print file path for scripts
readlink -f /home/vehu/backup/${bu_date}.tar.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants