📄 set_commands.c
字号:
/* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1998, 2000 University of Maryland at College Park * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of U.M. not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. U.M. makes no representations about the * suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Authors: the Amanda Development Team. Its members are listed in a * file named AUTHORS, in the root directory of this distribution. *//* * $Id: set_commands.c,v 1.26 2006/07/05 13:14:58 martinea Exp $ * * implements the "set" commands in amrecover */#include "amanda.h"#include "util.h"#include "amrecover.h"#ifdef SAMBA_CLIENTextern unsigned short samba_extract_method;#endif /* SAMBA_CLIENT *//* sets a date, mapping given date into standard form if needed */intset_date( char * date){ char *cmd = NULL; char *qdisk_path; clear_dir_list(); cmd = stralloc2("DATE ", date); if (converse(cmd) == -1) exit(1); /* if a host/disk/directory is set, then check if that directory is still valid at the new date, and if not set directory to mount_point */ if (disk_path != NULL) { qdisk_path = quote_string(disk_path); cmd = newstralloc2(cmd, "OISD ", qdisk_path); amfree(qdisk_path); if (exchange(cmd) == -1) exit(1); if (server_happy()) { suck_dir_list_from_server(); } else { g_printf(_("No index records for cwd on new date\n")); g_printf(_("Setting cwd to mount point\n")); disk_path = newstralloc(disk_path, "/"); /* fake it */ clear_dir_list(); } } amfree(cmd); return 0;}voidset_host( const char *host){ char *cmd = NULL; struct hostent *hp = NULL; char **hostp; int found_host = 0; char *uqhost = unquote_string(host); if (is_extract_list_nonempty()) { g_printf(_("Must clear extract list before changing host\n")); return; } /* * The idea here is to try as many permutations of the hostname * as we can imagine. The server will reject anything it doesn't * recognize. */ cmd = stralloc2("HOST ", uqhost); if (converse(cmd) == -1) exit(1); if (server_happy()) found_host = 1; /* * Try converting the given host to a fully qualified, canonical * name. */ if (!found_host) { if ((hp = gethostbyname(uqhost)) != NULL) { host = hp->h_name; g_printf(_("Trying host %s ...\n"), host); cmd = newstralloc2(cmd, "HOST ", host); if (converse(cmd) == -1) exit(1); if(server_happy()) found_host = 1; } } /* * Since we have them, try any CNAMEs that were traversed from uqhost * to the canonical name (this assumes gethostbyname was called above) */ if (!found_host) { if (hp) { for (hostp = hp->h_aliases; (host = *hostp) != NULL; hostp++) { g_printf(_("Trying host %s ...\n"), host); cmd = newstralloc2(cmd, "HOST ", host); if (converse(cmd) == -1) exit(1); if(server_happy()) { found_host = 1; break; } } } } /* Try looking up the canonical name of the host */ if (!found_host) { char *canonname; int result; result = resolve_hostname(uqhost, 0, NULL, &canonname); if (result == 0 && canonname) { host = canonname; g_printf(_("Trying host %s ...\n"), host); cmd = newstralloc2(cmd, "HOST ", host); if (converse(cmd) == -1) exit(1); if(server_happy()) found_host = 1; } } if(found_host) { dump_hostname = newstralloc(dump_hostname, host); amfree(disk_name); amfree(mount_point); amfree(disk_path); clear_dir_list(); } amfree(cmd); amfree(uqhost);}voidlist_host(void){ char *cmd = NULL; cmd = stralloc("LISTHOST"); if (converse(cmd) == -1) exit(1); amfree(cmd);}voidset_disk( char * dsk, char * mtpt){ char *cmd = NULL; char *qdsk; char *uqdsk; char *uqmtpt = NULL; if (is_extract_list_nonempty()) { g_printf(_("Must clear extract list before changing disk\n")); return; } /* if mount point specified, check it is valid */ if (mtpt != NULL) { uqmtpt = unquote_string(mtpt); if (*mtpt != '/') { g_printf(_("Mount point \"%s\" invalid - must start with /\n"), uqmtpt); amfree(uqmtpt); return; } } clear_dir_list(); uqdsk = unquote_string(dsk); qdsk = quote_string(uqdsk); cmd = stralloc2("DISK ", qdsk); amfree(qdsk); if (converse(cmd) == -1) exit(1); amfree(cmd); if (!server_happy()) return; disk_name = newstralloc(disk_name, uqdsk); if (mtpt == NULL) { /* mount point not specified */ if (*uqdsk == '/') { /* disk specified by mount point, hence use it */ mount_point = newstralloc(mount_point, uqdsk); } else { /* device name given, use '/' because nothing better */ mount_point = newstralloc(mount_point, "/"); } } else { /* mount point specified */ mount_point = newstralloc(mount_point, uqmtpt); } /* set the working directory to the mount point */ /* there is the possibility that there are no index records for the disk for the given date, hence setting the directory to the mount point will fail. Preempt this by checking first so we can write a more informative message. */ if (exchange("OISD /") == -1) exit(1); if (server_happy()) { disk_path = newstralloc(disk_path, "/"); suck_dir_list_from_server(); /* get list of directory contents */ } else { g_printf(_("No index records for disk for specified date\n")); g_printf(_("If date correct, notify system administrator\n")); disk_path = newstralloc(disk_path, "/"); /* fake it */ clear_dir_list(); } amfree(uqmtpt); amfree(uqdsk);}voidlist_disk( char * amdevice){ char *cmd = NULL; char *qamdevice, *uqamdevice; if(amdevice) { uqamdevice = unquote_string(amdevice); qamdevice = quote_string(uqamdevice); cmd = stralloc2("LISTDISK ", qamdevice); amfree(uqamdevice); amfree(qamdevice); if (converse(cmd) == -1) exit(1); amfree(cmd); } else { cmd = stralloc("LISTDISK"); if (converse(cmd) == -1) exit(1); amfree(cmd); }}voidlocal_cd( char *dir){ char *uqdir = unquote_string(dir); if (chdir(uqdir) == -1) { perror(uqdir); } amfree(uqdir);}voidcd_glob( char * glob){ char *regex; char *regex_path; char *s; char *uqglob; char *path_on_disk = NULL; if (disk_name == NULL) { g_printf(_("Must select disk before changing directory\n")); return; } uqglob = unquote_string(glob); regex = glob_to_regex(uqglob); dbprintf(_("cd_glob (%s) -> %s\n"), uqglob, regex); if ((s = validate_regexp(regex)) != NULL) { g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob); puts(s); amfree(regex); return; } /* * glob_to_regex() anchors the beginning of the pattern with ^, * but we will be tacking it onto the end of the current directory * in add_file, so strip that off. Also, it anchors the end with * $, but we need to match a trailing /, add it if it is not there */ regex_path = stralloc(regex + 1); amfree(regex); if(regex_path[strlen(regex_path) - 2] != '/' ) { regex_path[strlen(regex_path) - 1] = '\0'; strappend(regex_path, "/$"); } /* convert path (assumed in cwd) to one on disk */ if (strcmp(disk_path, "/") == 0) path_on_disk = stralloc2("/", regex_path); else { char *clean_disk_path = clean_regex(disk_path); path_on_disk = vstralloc(clean_disk_path, "/", regex_path, NULL); amfree(clean_disk_path); } cd_dir(path_on_disk, uqglob); amfree(regex_path); amfree(path_on_disk); amfree(uqglob);}voidcd_regex( char * regex){ char *s; char *uq_orig_regex;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -