Linux Tutorial | Matt Cooper - Open Source Support
Linux Tutorial | Matt Cooper - Open Source Support
Amazon AWS, Backup Tutorial

Automate EBS Volume Backups – AWS Cli+Bash

Simple bash script using the AWS Cli to backup EBS Volumes.

I used a free tier micro EC2 Amazon AMI to act as the backup generator.

AWS Interface

1. Create new policy with permission to create snapshots:

– Security, Identity & Compliance > IAM

– Policy > Create policy

– Create Your Own Policy

– Give a relevant name and insert the following into the Policy Document:

Continue reading

February 12, 2017by Matt Cooper
FacebookTwitterPinterestGoogle +Stumbleupon
Backup Tutorial, Proxmox Tutorial

Proxmox – add a second hard drive to node for Backups

Simplified steps to add a second hard drive to a Debian server running Proxmox.

Firstly physically install the Hard Drive in the server chassis.

Startup the server and run the following from commandline to find the device name for the disk:

fdisk -l

This should return something similar to this:


Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 2517 20217771 83 Linux
/dev/sda2 2518 2610 747022+ 5 Extended
/dev/sda5 2518 2610 746991 82 Linux swap / Solaris

Disk /dev/sdb: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

If it is the first new disk you have added it will more than likely be /dev/sdb as the device name.

Now we partition the disk:

cfdisk /dev/sdb

Select the following options:

  • New > Primary > Enter (use the size in MB already specified)
  • Write
  • Quit

Now we format the disk to the ext3 filesystem:

mkfs.ext3 /dev/sdb1 

Mount the drive to a new folder:

mkdir /mnt/backups
mount -t ext3 /dev/sdb1 /mnt/backups 

Lastly we add the disk to /etc/fstab so it auto-mounts when we reboot the machine:

 
/dev/sdb1 /mnt/backups ext3 defaults,errors=remount-ro 0 1 

That’s your drive mounted and ready to be added as backup storage in Proxmox.

To test: reboot the machine and confirm that the drive is still mounted.

January 8, 2014by Matt Cooper
FacebookTwitterPinterestGoogle +Stumbleupon
Backup Tutorial, CPanel Tutorial

CPanel – filesystem backup

Following on from our previous post (https://www.linuxtutorial.co.uk/cpanel-mysql-backup-script/) there is another script for the full backup of CPanel web directories.

The original post is taken from http://r00t3r.com/cpanel-full-backup-cron-script-for-automated-backups/ which contains a link to download the PHP files.

The main file to worry about is the config.php which contains a cpanel section:

// CPANEL ACCOUNT TO BACKUP
define( 'CPANEL_SERVER_ADDRESS',		'abc.def.ghj.mnp' );	// IP address or domain name for the server with the cPanel account
define( 'CPANEL_PORT_NUM',				'2083' );	// The port number for the cPanel. If you have problems, try 2082
define( 'CPANEL_ADMIN_USERNAME',		'admin-username' );	// the admin username for your cPanel account
define( 'CPANEL_ADMIN_PASSWORD',		'veryStrongPassword' ); // the admin password for your cPanel account

and the FTP server section:

define( 'FTP_SERVER_ADDRESS',			'npq.rst.uvw.xyz' );     // IP address or URL of the FTP server
define( 'FTP_SERVER_PORT',			'21' );			 // FTP(S) Port. Default is 21.
define( 'FTP_USERNAME',				'ftp-username' );	 // FTP Username
define( 'FTP_PASSWORD',				'ftp-password' );	 // FTP Password
define( 'FTP_PATH_TO_COPY',			'/ftp/path/to/copy/' );	 // FTP Path (where do you want to copy the files?)

Simply enter in your CPanel and FTP server account details to this PHP script.

Once in place setup the cron job to run on a regular basis e.g.

1 1 * * * php -q /home/user/path_to_phpscript/cpanelbackup.php
July 10, 2013by Matt Cooper
FacebookTwitterPinterestGoogle +Stumbleupon
Backup Tutorial, CPanel Tutorial

CPanel – mysql backup script (PHP)

Simple PHP MySQL backup script for CPanel. Create a php file and insert the following code:


<?
$datestamp = date("Y-m-d");// Current date to append to filename of backup file in format of YYYY-MM-DD

/* CONFIGURE THE FOLLOWING THREE VARIABLES TO MATCH YOUR SETUP */
$dbuser = "username";// Database username
$dbpwd = "password";// Database password
$dbname = "database";// Database name. Use --all-databases if you have more than one
$filename= "backup-$datestamp.sql.gz";// The name (and optionally path) of the dump file

$command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename";
$result = passthru($command);

/* CONFIGURE THE FOLLOWING FOUR VARIABLES TO MATCH YOUR FTP SETUP */
$ftp_server = "hostname";// Shouldn't have any trailing slashes and shouldn't be prefixed with ftp://
$ftp_port = "21";// FTP port - blank defaults to port 21
$ftp_username = "username";// FTP account username
$ftp_password = "password";// FTP account password - blank for anonymous

// set up basic connection
$ftp_conn = ftp_connect($ftp_server);

// Turn PASV mode on or off
ftp_pasv($ftp_conn, false);

// login with username and password
$login_result = ftp_login($ftp_conn, $ftp_username, $ftp_password);

// check connection
if ((!$ftp_conn) || (!$login_result))
{
echo "FTP connection has failed.";
echo "Attempted to connect to $ftp_server for user $ftp_username";
exit;
}
else
{
echo "Connected to $ftp_server, for user $ftp_username";
}

// upload the file
$upload = ftp_put($ftp_conn, $filename, $filename, FTP_BINARY);

// check upload status
if (!$upload)
{
echo "FTP upload has failed.";
}
else
{
echo "Uploaded $filename to $ftp_server.";
}

// close the FTP stream
ftp_close($ftp_conn);

unlink($filename);   //delete the backup file from the server
?>

Now add a cron job to trigger the backup script when required:


1 1 * * * php -q /home/user/path_to_phpscript/sqlbackup.php

The above code will trigger the backup to run at 1:01 a every day of the year.

Use a cron calculator to sepcify the time and days you would like your cron to run: http://www.csgnetwork.com/crongen.html

July 10, 2013by Matt Cooper
FacebookTwitterPinterestGoogle +Stumbleupon

About me

Hi, I'm Matt Cooper. I started this blog to pretty much act as a brain dump area for things I learn from day to day. You can contact me at: matt@linuxtutorial.co.uk

Recent Comments

  • Andrew on Export list of Amazon EC2 Instances to CSV
  • Matt Cooper on Proxmox – add a second hard drive to node for Backups
  • karis on Proxmox – add a second hard drive to node for Backups
  • Matt Cooper on Remote MySQL Database – Slow Connection
  • Matt Cooper on Bash script to send public IP address to Email

Categories

  • AdvancedTomato
  • Amazon AWS
  • Amazon Linux
  • Amazon S3
  • Apache
  • Apache Kafka
  • Backup Tutorial
  • Bash Scripting
  • Centos Tutorial
  • CloudFlare
  • Command line Tutorial
  • CPanel Troubleshooting
  • CPanel Tutorial
  • Debian Troubleshooting
  • Debian Tutorial
  • DKIM
  • Docker
  • EC2
  • ESXi
  • Faildows
  • Google Adwords
  • Google Analytics
  • Google Chromebook
  • Google Mail
  • graylog
  • IAM
  • imapsync
  • iRedmail Tutorial
  • ISPConfig3 Tutorial
  • Java
  • ldap
  • letsencrypt
  • MyDNS
  • MySQL Troubleshooting
  • MySQL Tutorial
  • Nest Install
  • Netbeans
  • Nginx
  • Nginx Troubleshooting
  • openssl
  • PCI Compliance
  • Percona
  • PHP
  • Plex Media Server Tutorial
  • Postfix
  • Proxmox Tutorial
  • Pure FTPd
  • Resourcespace Tutorial
  • Route 53
  • Rsync Tutorial
  • Security
  • Smoothwall Troubleshooting
  • Smoothwall Tutorial
  • SSH
  • tcpdump
  • Thunderbird
  • Tomcat Troubleshooting
  • Ubuntu Tutorial
  • Uncategorized
  • Unison
  • vmware
  • vzdump
  • WHM
  • Wireshark
  • Wordpress Troubleshooting
  • WordPress Tutorial

“See, you not only have to be a good coder to create a system like Linux, you have to be a sneaky bastard too." Linus Torvalds

© 2017 copyright www.linuxtutorial.co.uk // All rights reserved