为什么 Python 的 socket.getfqdn() 返回一个看起来像 IPv6 主机的长字符串,而不是 `hostname -f` 返回的内容?

Mat*_*ure 5 python backup amazon-s3

socket.getfqdn()为什么返回Python'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'而不是matt-mmf-macbook.local?

mlm@matt-mmf-macbook.local:~
$ python
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.getfqdn()
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa'
>>> 

mlm@matt-mmf-macbook.local:~
$ hostname
matt-mmf-macbook.local

mlm@matt-mmf-macbook.local:~
$ hostname -f
matt-mmf-macbook.local
Run Code Online (Sandbox Code Playgroud)

的意外输出socket.getfqdn()使我的口是心非备份失败,输出如下。我上次成功的口是心非备份是在 12 月 19 日。

mlm@matt-mmf-macbook.local:~
$ ~/config/bash/backup.sh
Reading globbing filelist /Users/mlm/config/bash/backup-include-matt-mmf-macbook.txt
Reading globbing filelist /Users/mlm/config/bash/backup-exclude-matt-mmf-macbook.txt
Local and Remote metadata are synchronized, no sync needed.
Warning, found the following remote orphaned signature files:
duplicity-new-signatures.20110929T140604Z.to.20110929T143209Z.sigtar.gpg
duplicity-new-signatures.20110929T143209Z.to.20110929T150055Z.sigtar.gpg
duplicity-new-signatures.20110929T150055Z.to.20110929T161503Z.sigtar.gpg
duplicity-new-signatures.20110929T161503Z.to.20110930T161505Z.sigtar.gpg
duplicity-new-signatures.20110930T161505Z.to.20111005T024235Z.sigtar.gpg
duplicity-new-signatures.20111005T024235Z.to.20111005T024907Z.sigtar.gpg
duplicity-new-signatures.20111005T024907Z.to.20111005T161508Z.sigtar.gpg
duplicity-new-signatures.20111005T161508Z.to.20111006T161509Z.sigtar.gpg
duplicity-new-signatures.20111006T161509Z.to.20111007T161507Z.sigtar.gpg
duplicity-new-signatures.20111007T161507Z.to.20111010T161511Z.sigtar.gpg
duplicity-new-signatures.20111010T161511Z.to.20111011T161507Z.sigtar.gpg
duplicity-new-signatures.20111011T161507Z.to.20111012T161510Z.sigtar.gpg
duplicity-new-signatures.20111012T161510Z.to.20111013T161505Z.sigtar.gpg
duplicity-new-signatures.20111013T161505Z.to.20111017T161506Z.sigtar.gpg
duplicity-new-signatures.20111017T161506Z.to.20111018T161505Z.sigtar.gpg
duplicity-new-signatures.20111018T161505Z.to.20111019T161506Z.sigtar.gpg
duplicity-new-signatures.20111019T161506Z.to.20111020T161506Z.sigtar.gpg
duplicity-new-signatures.20111020T161506Z.to.20111021T161511Z.sigtar.gpg
duplicity-new-signatures.20111021T161511Z.to.20111025T161507Z.sigtar.gpg
duplicity-new-signatures.20111025T161507Z.to.20111026T161510Z.sigtar.gpg
duplicity-new-signatures.20111026T161510Z.to.20111027T161506Z.sigtar.gpg
duplicity-new-signatures.20111027T161506Z.to.20111028T161511Z.sigtar.gpg
duplicity-new-signatures.20111028T161511Z.to.20111104T161506Z.sigtar.gpg
duplicity-new-signatures.20111104T161506Z.to.20111115T222417Z.sigtar.gpg
Last full backup date: Wed Nov 16 12:16:14 2011
Fatal Error: Backup source host has changed.
Current hostname: 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa
Previous hostname: matt-mmf-macbook.local

Aborting because you may have accidentally tried to backup two different data sets to the same remote location, or using the same archive directory.  If this is not a mistake, use the --allow-source-mismatch switch to avoid seeing this message

mlm@matt-mmf-macbook.local:~
$ 
Run Code Online (Sandbox Code Playgroud)

我的 backup.sh 包含:

#! /bin/bash

PATH=/usr/local/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:$PATH

. ~/config/bash/awskeys.sh

. $(type -p virtualenvwrapper.sh)
workon duplicity

ulimit -n 1024

duplicity \
    --encrypt-key DEADBEEF \
    --include-globbing-filelist ~/config/bash/backup-include-$(hostname -s).txt \
    --exclude-globbing-filelist ~/config/bash/backup-exclude-$(hostname -s).txt \
    / \
    s3://s3.amazonaws.com/backup-$(hostname -s)/
Run Code Online (Sandbox Code Playgroud)

Mat*_*ure 0

我导航到“系统偏好设置”>“网络”>“Wi-Fi”>“高级”>“TCP/IP”,并将“配置 IPv6”更改为:

Off
Run Code Online (Sandbox Code Playgroud)

到:

Automatically
Run Code Online (Sandbox Code Playgroud)

现在我得到了我所期望的:

mlm@matt-mmf-macbook.local:~
$ python -c 'import socket ; print socket.getfqdn()'
matt-mmf-macbook.local

mlm@matt-mmf-macbook.local:~
$ 
Run Code Online (Sandbox Code Playgroud)

我还注意到,更改为“自动”后,“关闭”不再是一个选项。