Mac automatically backs up data to the server

Source: Internet
Author: User

Requirements: Internal use of their own computer, home need to use another computer, so you want to back up the company's computer files, code to the server, home can be used

1 No password use SCP

(1) First step: Generate key pair, I use RSA key. Using the command "ssh-keygen-t RSA"
[[email protected] user1]$ ssh-keygen-t RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/HOME/USER1/.SSH/ID_RSA):
Created directory '/home/user1/.ssh '.
Enter passphrase (empty for no passphrase):
Enter same Passphrase again:
Your identification has been saved In/home/user1/.ssh/id_rsa.
Your public key has been saved in/home/user1/.ssh/id_rsa.pub.
The key fingerprint is:
E0:f0:3b:d3:0a:3d:da:42:01:6a:61:2f:6c:a0:c6:e7 [email protected]
[Email protected] user1]$

(2) The process of generating prompts to enter the key pair to save the location, directly enter, accept the default value on the line. You will then be prompted to enter a

A different password from your password, go directly to it and leave it empty. Of course, you can also enter one. (I am more lazy

, do not want to enter the password every time. This way, the key pair is generated.

Where the public key is saved in ~/.ssh/id_rsa.pub
Private key saved in ~/.ssh/id_rsa

Then change the. SSH directory permissions, using the command "chmod 755 ~/.ssh"
[Email protected] user1]$ chmod 755 ~/.ssh

(3) then copy the public key in this key pair to the machine you want to access and save it as

~/.ssh/authorized_keys.
[Email protected] user1]$ SCP ~/.ssh/id_rsa.pub Rh1:/home/user1/.ssh/authorized_keys
[email protected] ' s password:
Id_rsa.pub 100% 228 3.2mb/s 00:00
[Email protected] user1]$

2 scripting

(1) Version 1

#!/bin/shecho"[' Date ' +%y-%m-%d%h:%m:%s ']------------------------" /users/scg/DesktopSCP -R pan [email protected]:~/ 

3 Timed Call Script

Under Mac, you can use Launchctl to perform tasks on a regular basis.

The advantage of the LAUNCHCTL is that the minimum time interval is one second, because the plist is configured to achieve timed tasks.

Plist Script Storage path is/library/launchdaemons or/library/launchagents, the difference is the script after a path when the user login system will not be executed, the previous one as long as the system started, even if the user does not log on the system will be executed.

There are two ways to set the execution time of a script. One is to use Startinterval, which specifies how long the script will be executed per interval (in seconds), and the other using Startcalendarinterval, which can specify how many minutes, hours, days, weeks, and months time the script executes

<?XML version= "1.0" encoding= "UTF-8"?><!DOCTYPE plist Public "-//apple//dtd plist 1.0//en" "Http://www.apple.com/DTDs/PropertyList-1.0.dtd "><plistversion= "1.0"><Dict>    <Key>Label</Key>    <string>Com.meituan.scg.plist</string>    <Key>Programarguments</Key>    <Array>        <string>/users/scg/desktop/pan.sh</string>    </Array>    <Key>KeepAlive</Key>    <true/>    <Key>Runatload</Key>    <true/>    <Key>Startinterval</Key>    <integer>600</integer>    <Key>Standardoutpath</Key>    <string>/users/scg/desktop/pan.log</string>    <Key>Standarderrorpath</Key>    <string>/users/scg/desktop/pan_error.log</string></Dict></plist>

Description

(1) label here is to give the task name, here generally take plist file name, this name can not be duplicated with other plist.

(2) pan.sh is the script we're going to execute.

(3) Whether KeepAlive has been kept alive

(4) Startinterval every few seconds

See https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html for detailed parameters

I put this plist file in/library/launchdaemons. Need to do chown root *.plist and chgrp while *.plist

4 Perform this plist

    • For the task to take effect, the load command must be loaded before the plist
    • If the task is modified, you must first unload and then load again.
    • Start can test the task, which is executed immediately, regardless of the time
    • The task must be load before executing start and unload, otherwise the error
    • Stop can stop a task
    • You cannot write commands directly within programarguments, only through shell scripts.

Most commonly used commands:

    1. Loads the launchctl load -w ***.plist task -w , the option overwrites the invalid key in the plist file, and recommends adding
    2. Delete a tasklaunchctl unload -w ***.plist
    3. View the list launchctl list of tasks, which will show many tasks, and suggest filtering:launchctl list | grep ‘任务的部分名字‘
5 Todo (1) Boot from boot (2) Copy only those files that have been modified. (Requires a file to save the MD5 value of the file used, and then traverse each file, comparing the current MD5 value) http://blog.csdn.net/topasstem8/article/details/6551908/HTTP/ blog.chinaunix.net/uid-20613650-id-3269470.html Reference Article http://www.netingcn.com/tag/mac-os-crontabhttp:// my.oschina.net/jackin/blog/263024http://my.oschina.net/shede333/blog/470377http://honglu.me/2014/09/20/osx%e7% b3%bb%e7%bb%9f%e6%b7%bb%e5%8a%a0%e5%ae%9a%e6%97%b6%e4%bb%bb%e5%8a%a1/https://developer.apple.com/library/mac/ Documentation/darwin/reference/manpages/man5/launchd.plist.5.html
    • Add timed tasks under Mac-Liu Guotao's Column-Blog channel-csdn.net

    • Mac uses LAUNCHCTL timer to run programs-other-red and black Alliance

    • Schedule Jobs using Launchd

    • Mac OS timed launch a script perfect champions home Sina Blog

    • Mac OS recurring Task Configuration | When the network is in progress

    • Ken Wu's Blog»mac OS start Service optimization Advanced (LAUNCHD tuning)

    • Manage OSX Backend Services | Jxw3ng

    • Mac OSX boot-up configuration | Notepad

    • LINUX/MAC crontab command format with detailed example-Push cool

    • Running an SVN Server automatically in the Background

    • Launchd in MacOS

    • Mac OSX boot-up configuration

    • CRONTAB,SVN Mail, log garbled workaround (LINUX)

Mac automatically backs up data to the server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.