Created
September 2, 2023 03:30
-
-
Save keyle/88dfbf3ffda8f3dda2d056a54f1f0992 to your computer and use it in GitHub Desktop.
linux server backup script
This file contains 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 | |
#################################### | |
# Backup to tar | |
# inspired from | |
# https://ubuntu.com/server/docs/basic-backup-shell-script | |
#################################### | |
# What to backup. | |
backup_files="/home /var/spool/mail /etc /root /opt" | |
# Where to backup to. | |
dest="/backups" | |
# Create archive filename. | |
day=$(date '+%Y-%b-%d-%H:%M') | |
hostname=$(hostname -s) | |
archive_file="backup-$hostname-$day.tgz" | |
# Print start status message. | |
echo "Backing up $backup_files to $dest/$archive_file" | |
date | |
echo | |
# Backup the files using tar. | |
tar czf $dest/$archive_file $backup_files | |
# Print end status message. | |
echo | |
echo "Backup finished." | |
date | |
# Long listing of files in $dest to check file sizes. | |
ls -lach $dest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
copy locally
rsync -avP username@domain:/backups ~/Documents/LinuxBackups/domain