Linux Cron Backup Script – run once every month via cron

  Linux Cron Backup Script
==========

I set cron job with crontab -e for running 20:20 8th everyMonth any weekDay

Script appears below as backup-cron.sh,… feel free to COPY to your Linux VM for experimentation…

[root@server1 backup-cron]# crontab -l

20 20 8 * * /root/backup-cron.sh

[root@server1 backup-cron]# cd
[root@server1 ~]# cat backup-cron.sh
#!/usr/bin/bash

# script: /root/backup-cron.sh
# Author LEONIDAS SAVVIDES - LSEPOLIS123@GMAIL.COM
# script for backup auto with cron the Directory /etc/ to /root/backup-cron/etc-YYYY-MM-DD.tar.bz2 type
# of Archives once a month the 8th of each month 20:00

# Get Current date in format YYYY-MM-DD

DATE=`date +%Y-%m-%d`;

# directory to backup
BACKUP_THIS_DIR="/etc";

# save backups in the name /root/backup-cron/etc-DATE.tar.bz2

BACKUP_TO="/root/backup-cron/";

EXT=".tar.bz2";

BACKUP_FILE="etc-"$DATE$EXT; # not spaced

FULL_BACKUP_URI=$BACKUP_TO$BACKUP_FILE;  # not spaced

# Command to execute

tar jcvf $FULL_BACKUP_URI $BACKUP_THIS_DIR;  # all spaced with one space

# check if success or failure backup done
if [ $? -eq 0 ]; then
echo "Success"; mail -s "Success Backup on "$DATE root@localhost; exit 0;
else
echo "Failure"; mail -s "Failed Backup on "$DATE root@localhost; exit 1;
fi

# END OF THE SCRIPT

[root@server1 ~]#

any Question email me here : 

LSEPOLIS123@GMAIL.COM 



Logical Volumes (LVM), Disk Encryption, Creating a RAID Device

Logical Volumes (LVM), Disk Encryption, Creating a RAID Device
in Linux

================

In this post I show you these three (3) advanced procedures for CentOS 7 Linux Server…

I recommend try them in test VM Server and after in Production Server…

A – Disk Encryption

Exercise 22.1 Disk Encryption
In this exercise, you will encrypt a partition on the disk in order to provide a measure of security in the event that the hard drive or laptop is stolen. Reviewing the cryptsetup documentation first would be a good idea (man cryptsetup and cryptsetup –help).

1. Create a new partition for the encrypted block device with fdisk. Make sure the kernel is aware of the new partition table. A reboot will do this but there are other methods.
2. Format the partition with cryptsetup using LUKS for the crypto layer.
3. Create the un-encrypted pass through device by opening the encrypted block device, i.e., secret-disk.
4. Add an entry to /etc/crypttab so that the system prompts for the passphrase on reboot.
5. Format the filesystem as an ext4 filesystem.
6. Create a mount point for the new filesystem, i.e. /secret.
7. Add an entry to /etc/fstab so that the filesystem is mounted on boot.
8. Try and mount the encrypted filesystem.
9. Validate the entire configuration by rebooting.

Solution 22.1
1. $ sudo fdisk /dev/sda
Create a new partition (in the below /dev/sda4 to be concrete) and then either issue:
$ sudo partprobe -s
to have the system re-read the modified partition table, or reboot (which is far safer).
Note: If you can’t use a real partition, use the technique in the previous chapter to use a loop device or image file for the same purpose.
2. $ sudo cryptsetup luksFormat /dev/sda4
3. $ sudo cryptsetup luksOpen /dev/sda4 secret-disk
4. Add the following to /etc/crypttab:
secret-disk /dev/sda4
5. $ sudo mkfs -t ext4 /dev/mapper/secret-disk
6. $ sudo mkdir -p /secret
7. Add the following to /etc/fstab:
/dev/mapper/secret-disk /secret ext4 defaults 1 2
8. Mount just the one filesystem:
$ sudo mount /secret
or mount all filesystems mentioned in /etc/fstab:
$ sudo mount -a
9. Reboot.

B – Logical Volumes (LVM)

Exercise 23.1 Logical Volumes
We are going to create a logical volume using two 250 MB partitions. We are going to assume you have real partition-able disk space available.

1. Create two 250 MB partitions of type logical volume (8e).
2. Convert the partitions to physical volumes.
3. Create a volume group named myvg and add the two physical volumes to it. Use the default extent size.
4. Allocate a 300 MB logical volume named mylvm from volume group myvg.
5. Format and mount the logical volume mylvm at /mylvm
6. Use lvdisplay to view information about the logical volume.
7. Grow the logical volume and corresponding filesystem to 350 MB.

Solution 23.1
1. Execute:
$ sudo fdisk /dev/sda
using whatever hard disk is appropriate, and create the two partitions. While in fdisk, typing t will let you set the partition type to 8e. While it doesn’t matter if you don’t set the type, it is a good idea to lessen confusion. Use w to rewrite the partition table and exit, and then
$ sudo partprobe -s
or reboot to make sure the new partitions take effect.
2. Assuming the new partitions are /dev/sdaX and /dev/sdaY:
$ sudo pvcreate /dev/sdaX
$ sudo pvcreate /dev/sdaY
$ sudo pvdisplay
3. $ sudo vgcreate myvg /dev/sdaX /dev/sdaY
$ sudo vgdisplay
4. $ sudo lvcreate -L 300M -n mylvm myvg
$ sudo lvdisplay
5. $ sudo mkfs.ext4 /dev/myvg/mylvm
$ mkdir /mylvm
$ sudo mount /dev/myvg/mylvm /mylvm
If you want the mount to be persistent, edit /etc/fstab to include the line:
/dev/myvg/mylvm /mylvm ext4 defaults 0 0
6. $ sudo lvdisplay
7. $ df -h
$ sudo lvresize -r -L 350M /dev/myvg/mylvm
$ df -h
or
$ sudo lvresize -r -L +50M /dev/myvg/mylvm

C – Creating a RAID Device

Exercise 24.1 Creating a RAID Device
Normally when creating a RAID device we would use partitions on separate disks. However, for this exercise we probably don’t have such hardware available. Thus we will need to have two partitions on the same disk.
The process will be the same whether the partitions are on one drive or several (Although there is obviously little reason to actually create a RAID on a single device).

1. Create two 200 MB partitions of type raid (fd) either on your hard disk using fdisk, or using LVM.
2. Create a RAID 1 device named /dev/md0 using the two partitions.
3. Format the RAID device as an ext4 filesystem. Then mount it at /myraid and make the mount persistent.
4. Place the information about /dev/md0 in /etc/mdadm.conf file using mdadm. (Depending on your distribution, this file may not
previously exist.)
5. Examine /proc/mdstat to see the status of your RAID device.

Solution 24.1
1. If you need to create new partitions do:
$ sudo fdisk /dev/sda
and create the partitions as we have done before. For purposes of being definite, we will call them /dev/sdaX and
/dev/sdaY. You will need to run partprobe or kpartx or reboot after you are done to make sure the system is properly aware of the new partitions.
2. $ sudo mdadm -C /dev/md0 –level=1 –raid-disks=2 /dev/sdaX /dev/sdaY
3. $ sudo mkfs.ext4 /dev/md0
$ sudo mkdir /myraid
$ sudo mount /dev/md0 /myraid
and add to /etc/fstab
/dev/md0 /myraid ext4 defaults 0 0
4. $ mdadm –detail –scan >> /etc/mdadm.conf
5. $ cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 dm-14[1] dm-13[0]
204736 blocks [2/2] [UU]
unused devices: <none>
You should probably verify that with a reboot, the RAID volume is mounted automatically. When you are done, you probably will want to clean up by removing the line from /etc/fstab, and then getting rid of the partitions.

My first PC Build – Help & Tips

My first PC Build – Help & Tips – Learning Material Used

I recommend Intel Processors due to the fact are used by Apple Macs hence is supported/you-can-build a Hackintosh system or run a Virtual Machines(VM) and have as guest platform MacOS in addition to the normal Windows 10 or Linux VMs…
I recommend pickup the items you want but Not purchase them at the moment,… but await a Holiday Discount period to buy them under discount… I buy most items under Black Friday(BF) period at 20% Off. You can buy at BF if USA store or at Prime Day from Amazon or at Xmas etc

 

eBooks

  1. (c) 2009 , Build Your Own PC – Do-It-Yourself For Dummies [ Part-of-Tens useful Tips at the end of the eBook ]
  2. (c) 2017 , Troubleshooting and Maintaining Your PC All-in-One For Dummies – 3/e
  3. How to Buy/Choose a PC.PDF
  4. Windows 10 Anniversary Update Bible (2017), Wiley
  5. Linux Bible 9th Edition 2015, Wiley
  6. Build a Better PC – 2013
  7. https://s3.eu-central-1.amazonaws.com/leonidassavvides/rhel_5_6_7_cheatsheet_11x17_0417_jcs.pdf

Web-Sites

  1. https://choosemypc.net
  2. https://pcpartpicker.com
  3. http://techreport.com/review/23624/how-to-build-a-pc-the-tech-report-guide/
  4. https://www.singular.com.cy/ – buy components etc

Videos

  1. https://youtu.be/mqb4dDSPRP0 – Win 10 Pro for 15$ [best to install/activate immediately]
  2. How To Build The Best PC For Photo and Video Editing
    https://youtu.be/7D50mMbxB8o
  3. http://techreport.com/review/23624/how-to-build-a-pc-the-tech-report-guide/
  4. Watch “Avoiding Common PC Building Traps – Episode 1,2,3,4” on YouTube
    1. https://youtu.be/-plesrt8ZCs
    2. https://youtu.be/pPFEkL5GIiI
    3. https://youtu.be/CB9KiKrC-C4
    4. https://youtu.be/CkbgkOeqT0Q

================================

Coming Soon my Components & Setup Process