LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-22-2018, 07:04 PM   #1
mikedelo
Member
 
Registered: Mar 2004
Location: Staten Island, NY
Distribution: MX Linux
Posts: 63

Rep: Reputation: 0
Script for backup


I would like to start making a .tar of the /home/ directory and moving that file to my NAS nightly. Can this be done? I would assume it would need to be able to run as the superuser regardless if someone is logged on or not. I am running Ubuntu Mate 17.10.

Thanks!!
 
Old 01-22-2018, 08:15 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,597

Rep: Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690Reputation: 2690
1. Yes, your backup process will need superuser (root) authority to back up files and folders that belong to different users.

2. Why tar? Just curious, I have used tar for backups at times myself. Have you considered using a real backup application?

I set up a different server and ran burp for backups. It gave me generational restores to specific dates without wsted space. (burp does deduplication at the block level, and uses the rsync libraries so that a backup for a specific date does not waste space or bandwidth.)
 
Old 01-22-2018, 08:56 PM   #3
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,311
Blog Entries: 28

Rep: Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137Reputation: 6137
I use rsync, but I don't do regular backups because my computer usage doesn't warrant them. I do backups whenever I make significant changes.

I have heard good things about Back in Time, which is GUI frontend for rsync.
 
Old 01-23-2018, 01:48 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,295
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
I'd also use rsync. It would save a lot of time and wear and tear on the discs, relative to tar. You can also use it for incremental backups. There are a lot of tutorials about using the --link-dest option for that.
 
Old 01-23-2018, 06:17 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
tar is from the tape backup era and AFAIK it does not serve any purposes for backup anymore. (This is not to say tar isn't useful. In all other cases it is). If you backup to NAS it is way better to backup your individual files so you have instant access.

rsync is good, but not perfect regarding keeping multiple backups for different points in time.

rsnapshot, built around rsync plus --link-dest does provide this option. It keeps multiple backups and only storing the differences between subsequent backups.

Excellent for NAS & USB hard disk backups.

jlinkels

Last edited by jlinkels; 01-23-2018 at 08:32 AM.
 
Old 01-23-2018, 06:35 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
Quote:
Originally Posted by mikedelo View Post
I would like to start making a .tar of the /home/ directory and moving that file to my NAS nightly. Can this be done? I would assume it would need to be able to run as the superuser regardless if someone is logged on or not. I am running Ubuntu Mate 17.10.

Thanks!!
yes, it is possible, and just a single command (as root). But actually I don't know what is your real problem.
 
Old 01-23-2018, 02:06 PM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
why assume root/sudo is my Q, unless the storage is privileged...?

All of /home/ I guess is why.

Last edited by Habitual; 01-23-2018 at 02:07 PM.
 
Old 01-23-2018, 02:28 PM   #8
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,725

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
+1 for rsnapshot
We use it to backup a production server remotly daily. Been awhile since the first run, but I think that took about three hours. Now it backs up changes daily in about 11 minutes.
 
Old 01-23-2018, 02:52 PM   #9
mikedelo
Member
 
Registered: Mar 2004
Location: Staten Island, NY
Distribution: MX Linux
Posts: 63

Original Poster
Rep: Reputation: 0
Thanks for all your replies! Going with the RSYNC command, how do I go about writing a script to run daily, as root, regardless if someone is logged in. (I normally keep myself logged in).

Sorry for the newbie question, but that is what I am.
 
Old 01-23-2018, 03:03 PM   #10
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Say your destination directory is /srv/backups/home

As root: crontab -e
Code:
30 12 * * * /usr/bin/rsync -aX /home/ /srv/backups/home 1> /dev/null
will save all /home content into /srv/backups/home each day at 12:30 am
crontab editor is vi style, so to save, type: [esc] :wq

Last edited by keefaz; 01-23-2018 at 03:05 PM.
 
Old 01-23-2018, 06:40 PM   #11
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
The simple rsync command works if you want to backup below the root directory (such as /home in this example). And it fails surprisingly when the backup drive is not mounted. That is, disk space on the mount point partition will be filled up completely and services start to fail.

My preference is a short bash script which is called from cron.

Code:
#!/bin/bash

mount_point='/mnt/ext_daily'

# Find if the device is mounted
df -h | grep $mount_point > /dev/null
if [ $? -eq 0 ]
then
        rsync -uav --exclude='/mnt' --exclude='/proc' --exclude='/sys' --delete / /mnt/ext_daily > /var/log/rsync_daily
        echo "mount point $mount_point exists, rsync started"
else
        echo "Error: mount point $mount_point does not exist, rsync operation skipped"
fi
Echo statements go into /var/log/syslog if executed from cron. Double check the source and destination dir in the rsync command if you use --delete. Better run the first time without --delete until you are sure source and destination are correct.

The command in /etc/crontab:
Code:
59 4   * * *    root    /bin/sh /root/rsync_daily.sh
Note that you use either root's crontab with crontab -e as in the example above. Or you edit /etc/crontab directly. The syntax is slightly different as the 6th column specifies the user which executes the command.

jlinkels

Last edited by jlinkels; 01-23-2018 at 06:44 PM.
 
Old 01-24-2018, 04:14 AM   #12
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,474

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Take a look at http://dirvish.org/ it uses rsync but also allows you to create differential/versional backups, so you can go back to files at different points in time easily and without backup up everything every single time.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
backup script amartlk Linux - Newbie 6 02-10-2012 11:04 PM
What happens with backup-manager.org (very useful backup script)? Murz Linux - Software 3 07-27-2010 06:46 AM
Newbie trying to write a simple backup script to backup a single folder Nd for school stryker759a Linux - Newbie 2 09-16-2009 08:52 AM
Need help with script to organise files into folders as part of DVD backup script jasybee2000 Linux - Newbie 5 06-15-2009 07:29 PM
how to create backup MYSQL Script to backup my database for every 1hour RMLinux Linux - Newbie 3 11-20-2008 10:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration