Created
August 20, 2018 05:04
-
-
Save Fechin/fb0283f80c0c759233094a2aa82934d0 to your computer and use it in GitHub Desktop.
Backup file or directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#################################### | |
# An backup script. | |
# example: | |
# > sh backup.sh /var/www/hexo | |
# > _var_www_hexo-20180813102904.tgz | |
#################################### | |
# What to backup. | |
backup_dir=${1:-licensez} | |
# Where to backup to. | |
dest="backup" | |
mkdir -p $dest | |
# Create archive filename. | |
day=$(date +%Y%m%d%H%M%S) | |
archive_file="$(sed 's/\//_/g' <<< "$backup_dir")-$day.tgz" | |
# Print start status message. | |
echo "Backing up $backup_dir to $dest/$archive_file" | |
# Backup the files using tar. | |
tar czf $dest/$archive_file $backup_dir | |
# Long listing of files in $dest to check file sizes. | |
ls -lh $dest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment