-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbackup.sh
34 lines (26 loc) · 1.2 KB
/
backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Javier Ferrándiz Fernández - 28/07/2023 - https://github.com/javisys
# If we want to make it more complete we can use the tools rsync, borgbackup, rsnapshot, duplicity.
# They offer options to perform full, differential and incremental backups in a more automated and secure way.
# These tools will allow you to create a more sophisticated backup system suitable for your specific needs.
# Check if current user is sudo (administrator)
if [ "$(id -u)" -ne 0 ];
then
echo "This script must be run with superuser privileges."
exit 1
fi
# Directory where backups will be stored
backup_dir="/var/backups"
# Backup file name
backup_fileN="backup-$(date +%Y%m%d%H%%M%S).tar.gz"
# Create backup directory if it does not exist
mkdir -p "$backup_dir"
# Create a complete backup of the entire system using "tar"
tar czf "$backup_dir/$backup_fileN --exclude="$backup_dir" --exclude=/proc --exclude=/sys --exclude=/dev --exclude=/run --exclude=/mnt --exclude=/media --exclude=/lost+found --exclude=/tmp --exclude=/var/tmp --exclude=/var/run ."
# Verify if the backup was performed correctly
if [ "$?" -eq 0 ];
then
echo "Full backup successfully completed: $backup_fileN"
else
echo "Backup failed"
fi