Category: FreeBSD
Backup with dump on FreeBSD
It is very important to make backups. This script is partially finalized by me. Backup image with maximum file compression. The backups will be stored on a separate hard drive in the directory (/hdd2/backup/backupd/).
Example of a script that backs up the entire disk:
#!/bin/sh
echo 'Started copying root partition'
# The date will be added to the year file.month.day
DATE=`date +%Y.%m.%d`
echo 'Copy root partition /'
dump -0 -L -f - / | gzip -9 > /hdd2/backup/backupd/root.${DATE}.img.gz
echo 'Section copied. Backup is done'
Only the path and execution date of the script in /etc/crontab change for weekly, monthly, and yearly backups.
An example of my crontab file:
# /etc/crontab - root's crontab for FreeBSD
#
# $FreeBSD: release/10.0.0/etc/crontab 194170 2009-06-14 06:37:19Z brian $
#
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin
#
#minute hour mday month wday who command
#
*/5 * * * * root /usr/libexec/atrun
# Backup Files (Daily backup done at 03: 30 -
# when everyone is asleep and the load on the server is minimal)
30 03 * * * root /root/backupday.sh
# Monthly backup is done every 25th day at 04: 30 (after daily)
30 04 25 * * root /root/backupmth.sh
#
# Backup WEB
30 02 * * * root /root/backupwebd.sh
00 03 25 * * root /root/backupwebm.sh
#
# Delete backup (Delete backup web server at 05: 00 , root directory at 05: 30)
00 05 * * * root /root/dbweb.sh
30 05 * * * root /root/dbroot.sh
#
# Save some entropy so that /dev/random can re-seed on boot.
*/11 * * * * operator /usr/libexec/save-entropy
#
# Rotate log files every hour, if necessary.
0 * * * * root newsyslog
#
# Perform daily/weekly/monthly maintenance.
1 3 * * * root periodic daily
15 4 * * 6 root periodic weekly
30 5 1 * * root periodic monthly
#
# Adjust the time zone if the CMOS clock keeps local time, as opposed to
# UTC time. See adjkerntz(8) for details.
1,31 0-5 * * * root adjkerntz -a
Backing up sites and databases:
#!/bin/sh
# Selective backup of folders, files, and databases.
#
# Remember the value of the current date in the variable DATE. Further used
# DATE to form the name of the archive files.
DATE=`date +%Y.%m.%d`
#
# Specify a folder where to put all the files. Change to suit your needs.
# The specified folder must exist and be writable.
# ARCHSTORE='/path/to/archives'
# For example, use the /backup folder.
ARCHSTORE=' /hdd2/backup/web/day'
##### Back up folders and files.
#
# For example, copy and archive the /etc folder and the /usr/home folder.
# You need to change the path to the source data and the name of the resulting archive
# depending on your needs. The number of copy command blocks will be
# equals the number of files and folders to archive.
# Custom variables:
# PATHNAME='/pathname/file_or_directory'
# ARCHNAME='archive_name'
#
### Start of the file and folder copy block.
# Set the data path and archive name. Change as needed.
# site.com
PATHNAME='/usr/local/www/site.com'
ARCHNAME='site.com'
# The process of backing up a folder or file.
echo "Started copying folder ${PATHNAME}"
tar -czf ${ARCHSTORE}/${ARCHNAME}.${DATE}.tar.gz ${PATHNAME}
echo "${PATHNAME} archived, waiting 4 seconds"
sleep 4
### End of copy block
echo "Backup files and folders is done!."
##### End of backup folders and files
##########################################################################################
##### Backup mysql databases.
#
# To back up databases, you must specify a name and
# database user password, name and destination archive name.
#
# The number of database copy blocks will match
# the number of databases we need to copy and archive.
# Custom variables:
# DBUSER='user_name'
# DBLOGIN='password_to_databese'
# DBNAME='database_name'
# ARCHNAME='archive_name'
#
# For example-archive the database called mysql on behalf of the user
# root with password abcd and archive name mysql_sql_dat_sozdaniya. Indispensably
# change to suit your needs.
#
### Start of the MySQL database backup block.
# Set the name, user password, database name and archive name.
# mysql
DBUSER='root'
DBLOGIN='password'
DBNAME='mysql'
ARCHNAME='mysql'
#
# The process of backing up the database
echo "Databese backup is started ${DBNAME}."
/usr/local/bin/mysqldump -u${DBUSER} -p${DBLOGIN} ${DBNAME} > ${ARCHSTORE}/${ARCHNAME}.sql
tar -czf ${ARCHSTORE}/${ARCHNAME}_sql_${DATE}.tar.gz ${ARCHSTORE}/${ARCHNAME}.sql
rm ${ARCHSTORE}/${ARCHNAME}.sql
echo "Database backup ${DBNAME} is done!"
### End of MySQL database backup block.
### Start of the MySQL database backup block.
# Set the name, user password, database name and archive name.
# site.com
DBUSER='siteadmin'
DBLOGIN='siteadminpassword'
DBNAME='siteadmin'
ARCHNAME='siteadmin'
#
# The process of backing up the database
echo "Databese backup is started ${DBNAME}."
/usr/local/bin/mysqldump -u${DBUSER} -p${DBLOGIN} ${DBNAME} > ${ARCHSTORE}/${ARCHNAME}.sql
tar -czf ${ARCHSTORE}/${ARCHNAME}_sql_${DATE}.tar.gz ${ARCHSTORE}/${ARCHNAME}.sql
rm ${ARCHSTORE}/${ARCHNAME}.sql
echo "Database backup ${DBNAME} is done!"
### End of MySQL database backup block.
echo "All backup is created!"
##### End of database backup.
Script file deletion (in my case, backups):
#!/bin/sh
# Looking for file older than 7 days
find /hdd2/backup/backupd -type f -Btime +7 -delete
sleep 4
echo "Backup successfully deleted."
Posted: 2017-02-23
2021-05-10 11:56:34
Kvvillcaw
<a href=https://chimmed.ru/products/4-allylanisole-98-id=280790>4 Аллиланизол 98 процентов купить онлайн Интернет магазин ХИММЕД</a> Tegs: 4 Акрилоилморфолин 97 процентов купить онлайн Интернет магазин ХИММЕД https://chimmed.ru/products/4-acryloylmorpholine-97-id=339205 <u>Циклогексилизоцианид 99 процентов купить онлайн Интернет магазин ХИММЕД</u> <i>Циклогексилизоцианат 98 процентов купить онлайн Интернет магазин ХИММЕД</i> <b>Циклогексилдифенилфосфин 98 процентов купить онлайн Интернет магазин ХИММЕД</b>