conciseusa / backup-scripts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

To clone:
git clone https://github.com/conciseusa/backup-scripts.git

This is an effort to roll up the various backup scripts I have written over the years.

Sad I need to write my own scripts for something so common as making backups, but some solutions I found lacked the control I needed, or worse, I would get everything working, and the author of the script would make a breaking change and I would need to waste way too much time reworking and retesting the solution. At some point I gave up a wrote my own.

Not too much here, as this is mostly a wrapper around common commands like rsync and tar, and some simple job control and logging code. But I am posting to make it easy to deploy to my systems, and for my friends that use it in their small businesses.

setup.sh creates a config dir in the parent dir and copies in the bujobs.sh file that can be modified to run the needed jobs. It has some sample jobs that write to the tmp dir.

Much of the work can be setting up the source and/or destination targets. Below is a cheatsheet of commands used to set up targets. It may, or may not, be helpful depending on the goal.
Common scenarios are cleaning up a hard drive with data on it and formatting it to hold backup data,
and connecting to a NAS to backup data on the NAS, or storing backup data on the NAS.

Add drive and reformat:
sudo lsblk # see disks, add -f see type
Replace /dev/sdx with the drive you want to wipe, if it has data already, and reformat
sudo shred -vf -n 1 /dev/sdx # not fast, better then wipe, wipe was going to take a very long time
sudo fdisk -l # see partitions
sudo fdisk /dev/sdx # command ‘n’, 'p', enter, enter, enter / p to preview, w to write changes - create a partition

If "fdisk: DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors"
sudo parted /dev/sdx
(parted) mklabel gpt
(parted) print
(parted) quit
sudo reboot now, log back in

sudo mkfs -t ext4 /dev/sdx1
/dev/sdx1 should be ready to use, but not mounted.

sudo blkid # Listing all UUIDs, used drive model to name mount point, can choose any valid filename
fstab has many tutorials, basic use below
Sample line in /etc/fstab so mounts at startup - sudo nano /etc/fstab
UUID="becfc46b-d6bc-4abd-9eb9-8d4dfd441fe1" /mnt/ST4000NM0033-9ZM ext4 defaults 0 0

Create data dir and open to current user so crontab does not need to run as root:
sudo mkdir -p /mnt/ST4000NM0033-9ZM/data # create area for backups
cd /mnt/ST4000NM0033-9ZM
sudo chown -R $USER:$USER data
sudo chmod -R 770 data

mount -t ext4 # see mounts, mount -t nfs4 see nfs/nas mounts
sudo umount /data # disconnect mount
sudo mount -av # run fstab

Connect to NFS target:
https://linuxize.com/post/how-to-mount-an-nfs-share-in-linux/
Installing NFS client on Ubuntu and Debian:
sudo apt update
sudo apt install nfs-common
sudo mkdir /var/backups # Create mount point
sudo nano /etc/fstab
file system dir type options dump pass
10.10.0.10:/nasdata /var/backups nfs defaults 0 0
sudo mount -av # run fstab

du -h --max-depth=3 # Review size of data

If the backup server is placed in an out of the way location,
it can be helpful to have remote access to the GUI.
Different solutions seem to work, then stop working over the years(VNC, NoMachine, etc.).
RDP seems to be working well as of 2023 on Mint Linux
sudo apt install xrdp xorgxrdp -y
echo env -u SESSION_MANAGER -u DBUS_SESSION_BUS_ADDRESS cinnamon-session>~/.xsession
Thanks for the setup guide: https://www.rootisgod.com/2020/Using-RDP-With-Linux-Mint-20-Cinnamon/

About

License:MIT License


Languages

Language:Shell 100.0%